Use SESSION_NOT_RELIABLE when no messages received
When a WebSocket session is closed after not having received any messages, we'll use SESSION_NOT_RELIABLE to indicate to other parts of the session closing code not to send anything further (e.g. SockJS "Go Away!" frame). Issue: SPR-11884
This commit is contained in:
@@ -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.
|
||||
*
|
||||
* <p><strong>NOTE:</strong> 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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user