Fix condition in SubProtocolWebSocketHandler
Issue: SPR-11884
This commit is contained in:
parent
9880d2b5f4
commit
2b1ff4c5db
|
@ -70,7 +70,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
|
||||||
* connection isn't doing well (proxy issue, slow network?) and can be closed.
|
* connection isn't doing well (proxy issue, slow network?) and can be closed.
|
||||||
* @see #checkSessions()
|
* @see #checkSessions()
|
||||||
*/
|
*/
|
||||||
private final int TIME_TO_FIRST_MESSAGE = 60 * 1000;
|
private static final int TIME_TO_FIRST_MESSAGE = 60 * 1000;
|
||||||
|
|
||||||
|
|
||||||
private final Log logger = LogFactory.getLog(SubProtocolWebSocketHandler.class);
|
private final Log logger = LogFactory.getLog(SubProtocolWebSocketHandler.class);
|
||||||
|
@ -298,10 +298,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
|
||||||
if (holder != null) {
|
if (holder != null) {
|
||||||
holder.setHasHandledMessages();
|
holder.setHasHandledMessages();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// Should never happen
|
|
||||||
throw new IllegalStateException("Session not found: " + session);
|
|
||||||
}
|
|
||||||
checkSessions();
|
checkSessions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,7 +362,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
|
||||||
*/
|
*/
|
||||||
private void checkSessions() throws IOException {
|
private void checkSessions() throws IOException {
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
if (!isRunning() && currentTime - this.lastSessionCheckTime < TIME_TO_FIRST_MESSAGE) {
|
if (!isRunning() || (currentTime - this.lastSessionCheckTime < TIME_TO_FIRST_MESSAGE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.sessionCheckLock.tryLock()) {
|
if (this.sessionCheckLock.tryLock()) {
|
||||||
|
@ -376,7 +372,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
long timeSinceCreated = currentTime - holder.getCreateTime();
|
long timeSinceCreated = currentTime - holder.getCreateTime();
|
||||||
if (holder.hasHandledMessages() || timeSinceCreated < TIME_TO_FIRST_MESSAGE) {
|
if (timeSinceCreated < TIME_TO_FIRST_MESSAGE) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
WebSocketSession session = holder.getSession();
|
WebSocketSession session = holder.getSession();
|
||||||
|
|
|
@ -165,6 +165,7 @@ public class SubProtocolWebSocketHandlerTests {
|
||||||
new DirectFieldAccessor(sessions.get("id1")).setPropertyValue("createTime", sixtyOneSecondsAgo);
|
new DirectFieldAccessor(sessions.get("id1")).setPropertyValue("createTime", sixtyOneSecondsAgo);
|
||||||
new DirectFieldAccessor(sessions.get("id2")).setPropertyValue("createTime", sixtyOneSecondsAgo);
|
new DirectFieldAccessor(sessions.get("id2")).setPropertyValue("createTime", sixtyOneSecondsAgo);
|
||||||
|
|
||||||
|
this.webSocketHandler.start();
|
||||||
this.webSocketHandler.handleMessage(session1, new TextMessage("foo"));
|
this.webSocketHandler.handleMessage(session1, new TextMessage("foo"));
|
||||||
|
|
||||||
assertTrue(session1.isOpen());
|
assertTrue(session1.isOpen());
|
||||||
|
|
Loading…
Reference in New Issue