diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java index 9733e7f2a5..9ea0dc5652 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/CloseStatus.java @@ -135,11 +135,10 @@ public final class CloseStatus { /** - * Indicates that a session has become unreliable (e.g. timed out while sending - * a message) and extra care should be exercised while closing the session in - * order to avoid locking additional threads. - * - *

NOTE: Spring Framework specific status code. + * A status code for use within the framework the indicate a session has + * become unreliable (e.g. timed out while sending a message) and extra + * care should be exercised, e.g. avoid sending any further data to the + * client that may be done during normal shutdown. */ public static final CloseStatus SESSION_NOT_RELIABLE = new CloseStatus(4500); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java index c8d624f520..4ffb57d509 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java @@ -356,8 +356,13 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, } /** - * Periodically check sessions to ensure they have received at least one - * message or otherwise close them. + * When a session is connected through a higher-level protocol it has a chance + * to use heartbeat management to shut down sessions that are too slow to send + * or receive messages. However, after a WebSocketSession is established and + * before the higher level protocol is fully connected there is a possibility + * for sessions to hang. This method checks and closes any sessions that have + * been connected for more than 60 seconds without having received a single + * message. */ private void checkSessions() throws IOException { long currentTime = System.currentTimeMillis(); @@ -380,7 +385,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, "Closing " + holder.getSession() + "."); } try { - session.close(CloseStatus.PROTOCOL_ERROR); + session.close(CloseStatus.SESSION_NOT_RELIABLE); } catch (Throwable t) { logger.error("Failure while closing " + session, t);