Commit 5299db38 authored by Phillip Webb's avatar Phillip Webb

Fix deadlock when calling LiveReloadServer.stop()

Update LiveReloadServer so that different synchronization blocks are
used for the sockets and connection lists. Prior to this commit calling
`LiveReloadServer.stop()` would always result in a 60 second delay since
`stop()` owned the monitor add `removeConnection()` (called from a
different thread) needs it to remove the active connection.

Fixes gh-7749
parent 42cfef8e
...@@ -199,7 +199,7 @@ public class LiveReloadServer { ...@@ -199,7 +199,7 @@ public class LiveReloadServer {
} }
private void closeAllConnections() throws IOException { private void closeAllConnections() throws IOException {
synchronized (this.monitor) { synchronized (this.connections) {
for (Connection connection : this.connections) { for (Connection connection : this.connections) {
connection.close(); connection.close();
} }
...@@ -211,25 +211,27 @@ public class LiveReloadServer { ...@@ -211,25 +211,27 @@ public class LiveReloadServer {
*/ */
public void triggerReload() { public void triggerReload() {
synchronized (this.monitor) { synchronized (this.monitor) {
for (Connection connection : this.connections) { synchronized (this.connections) {
try { for (Connection connection : this.connections) {
connection.triggerReload(); try {
} connection.triggerReload();
catch (Exception ex) { }
logger.debug("Unable to send reload message", ex); catch (Exception ex) {
logger.debug("Unable to send reload message", ex);
}
} }
} }
} }
} }
private void addConnection(Connection connection) { private void addConnection(Connection connection) {
synchronized (this.monitor) { synchronized (this.connections) {
this.connections.add(connection); this.connections.add(connection);
} }
} }
private void removeConnection(Connection connection) { private void removeConnection(Connection connection) {
synchronized (this.monitor) { synchronized (this.connections) {
this.connections.remove(connection); this.connections.remove(connection);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment