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
This commit is contained in:
Phillip Webb 2016-12-24 11:00:51 -08:00
parent 42cfef8ec1
commit 5299db3806
1 changed files with 11 additions and 9 deletions

View File

@ -199,7 +199,7 @@ public class LiveReloadServer {
}
private void closeAllConnections() throws IOException {
synchronized (this.monitor) {
synchronized (this.connections) {
for (Connection connection : this.connections) {
connection.close();
}
@ -211,25 +211,27 @@ public class LiveReloadServer {
*/
public void triggerReload() {
synchronized (this.monitor) {
for (Connection connection : this.connections) {
try {
connection.triggerReload();
}
catch (Exception ex) {
logger.debug("Unable to send reload message", ex);
synchronized (this.connections) {
for (Connection connection : this.connections) {
try {
connection.triggerReload();
}
catch (Exception ex) {
logger.debug("Unable to send reload message", ex);
}
}
}
}
}
private void addConnection(Connection connection) {
synchronized (this.monitor) {
synchronized (this.connections) {
this.connections.add(connection);
}
}
private void removeConnection(Connection connection) {
synchronized (this.monitor) {
synchronized (this.connections) {
this.connections.remove(connection);
}
}