Browse Source

Fix inconsistent synchronization in HttpTunnelServer.ServerThread

Previously, ServerThread.lastHttpRequestTime was written while
synchronized on this.httpConnections but was read without
synchronization. This could lead to a read of the field producing the
wrong value and cause premature connection timeout.

This commit moves the call to checkNotDisconnected into a block that
sychronizes on this.httpConnections, thereby ensuring that
lastHttpRequestTime can be read safely.

Closes gh-4668
pull/4548/merge
Andy Wilkinson 10 years ago
parent
commit
256cad8980
  1. 2
      spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServer.java

2
spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/HttpTunnelServer.java

@ -274,8 +274,8 @@ public class HttpTunnelServer {
} }
private void closeStaleHttpConnections() throws IOException { private void closeStaleHttpConnections() throws IOException {
checkNotDisconnected();
synchronized (this.httpConnections) { synchronized (this.httpConnections) {
checkNotDisconnected();
Iterator<HttpConnection> iterator = this.httpConnections.iterator(); Iterator<HttpConnection> iterator = this.httpConnections.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
HttpConnection httpConnection = iterator.next(); HttpConnection httpConnection = iterator.next();

Loading…
Cancel
Save