From f22fcde971168cca275cbc1b632fe96a4de7e143 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 25 Sep 2015 09:43:25 -0700 Subject: [PATCH] 474936 - WebSocketSessions are not always cleaned out from openSessions + Calling onSessionOpen() before App.onOpen() This helps, as there is a race for the onSessionOpen() in the original behavior with short lived sockets. The short lived socket could handle onSessionClosed() before onSessionOpen() had a chance, making the close fail to remove the session from openSessions, and then the slower add occurs later, adding it into the openSession + Minor cleanup in IOState --- .../jetty/websocket/common/WebSocketSession.java | 6 ++++-- .../eclipse/jetty/websocket/common/io/IOState.java | 12 +++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index 9646f514187..68c63ddf935 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -400,12 +400,14 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web // confirmed close of local endpoint notifyClose(close.getStatusCode(),close.getReason()); break; - case OPEN: + case CONNECTED: // notify session listeners for (SessionListener listener : sessionListeners) { try { + if (LOG.isDebugEnabled()) + LOG.debug("{}.onSessionOpen()", listener.getClass().getSimpleName()); listener.onSessionOpened(this); } catch (Throwable t) @@ -435,7 +437,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web // Connect remote remote = new WebSocketRemoteEndpoint(connection,outgoingHandler,getBatchMode()); - + // Open WebSocket websocket.openSession(this); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/IOState.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/IOState.java index bcd172cf938..de75cecc0c2 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/IOState.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/IOState.java @@ -250,6 +250,9 @@ public class IOState synchronized (this) { closeInfo = close; + + // Turn off further output + outputAvailable = false; boolean in = inputAvailable; boolean out = outputAvailable; @@ -257,9 +260,7 @@ public class IOState { closeHandshakeSource = CloseHandshakeSource.LOCAL; } - out = false; - outputAvailable = false; - + LOG.debug("onCloseLocal(), input={}, output={}",in,out); if (!in && !out) @@ -319,6 +320,9 @@ public class IOState } closeInfo = close; + + // turn off further input + inputAvailable = false; boolean in = inputAvailable; boolean out = outputAvailable; @@ -326,8 +330,6 @@ public class IOState { closeHandshakeSource = CloseHandshakeSource.REMOTE; } - in = false; - inputAvailable = false; if (LOG.isDebugEnabled()) LOG.debug("onCloseRemote(), input={}, output={}",in,out);