You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid locking in WebSocket session "close" callback
When processing a "close" notification from the server make an effort
to cancel any outstanding heartbeat but avoid going as far as acquiring
the responseLock since the server itself may already hold a lock of its
own leading to a potential deadlock.
The heartbeat task is now also further protected with an isClosed()
check in case the heartbeat does not get cancelled in a concurrent
scenario.
Issue: SPR-14917
Copy file name to clipboardExpand all lines: spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractSockJsSession.java
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -396,7 +396,12 @@ public final void delegateConnectionClosed(CloseStatus status) throws Exception
396
396
if (!isClosed()) {
397
397
try {
398
398
updateLastActiveTime();
399
-
cancelHeartbeat();
399
+
// Avoid cancelHeartbeat() and responseLock within server "close" callback
400
+
ScheduledFuture<?> future = this.heartbeatFuture;
401
+
if (future != null) {
402
+
this.heartbeatFuture = null;
403
+
future.cancel(false);
404
+
}
400
405
}
401
406
finally {
402
407
this.state = State.CLOSED;
@@ -446,7 +451,7 @@ private class HeartbeatTask implements Runnable {
Copy file name to clipboardExpand all lines: spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/SockJsSessionTests.java
0 commit comments