java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session

Spring JIRA | Rossen Stoyanchev | 3 years ago
  1. 0

    Currently NativeWebSocketSession implementations delegate for data available from the native session and contain fields for data that may not be available that way. This is okay however the underlying session can raise exceptions if any of its methods are called after it is closed, e.g.: {code:java} java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session at org.apache.tomcat.websocket.WsSession.checkState(WsSession.java:652) at org.apache.tomcat.websocket.WsSession.getUserPrincipal(WsSession.java:581) at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.getPrincipal(StandardWebSocketSession.java:123) at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.getPrincipal(WebSocketServerSockJsSession.java:73) at org.springframework.web.socket.messaging.StompSubProtocolHandler.afterSessionEnded(StompSubProtocolHandler.java:364) at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:352) at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:347) {code} This is an issue for fields such as the accepted sub-protocol and the Principal that get invoked from SubProtocolWebSocketHandler and StompSubProtocolHandler after the session is closed. We can ensure that those methods never delegate by storing the information internally as fields.

    Spring JIRA | 3 years ago | Rossen Stoyanchev
    java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session
  2. 0

    Currently NativeWebSocketSession implementations delegate for data available from the native session and contain fields for data that may not be available that way. This is okay however the underlying session can raise exceptions if any of its methods are called after it is closed, e.g.: {code:java} java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session at org.apache.tomcat.websocket.WsSession.checkState(WsSession.java:652) at org.apache.tomcat.websocket.WsSession.getUserPrincipal(WsSession.java:581) at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.getPrincipal(StandardWebSocketSession.java:123) at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.getPrincipal(WebSocketServerSockJsSession.java:73) at org.springframework.web.socket.messaging.StompSubProtocolHandler.afterSessionEnded(StompSubProtocolHandler.java:364) at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:352) at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:347) {code} This is an issue for fields such as the accepted sub-protocol and the Principal that get invoked from SubProtocolWebSocketHandler and StompSubProtocolHandler after the session is closed. We can ensure that those methods never delegate by storing the information internally as fields.

    Spring JIRA | 3 years ago | Rossen Stoyanchev
    java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session
  3. 0

    How To Configure Spring Websockets With CloudAMQP

    Stack Overflow | 3 years ago | Ryan Baxter
    java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How To Configure Spring Websockets With CloudAMQP

    itquestionz.com | 1 year ago
    java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session
  6. 0

    Using spring websockets, our log seem full of exceptions like these: {code} [stdout] 16:05:18,957 ERROR clientOutboundChannel-13 handler.ExceptionWebSocketHandlerDecorator:92 - Unhandled error for ExceptionWebSocketHandlerDecorator [delegate=LoggingWebSocketHandlerDecorator [delegate=org.springframework.web.socket.messaging.SubProtocolWebSocketHandler@315934c3]] [stdout] java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session [stdout] at org.apache.tomcat.websocket.WsSession.checkState(WsSession.java:653) [stdout] at org.apache.tomcat.websocket.WsSession.getUserPrincipal(WsSession.java:582) [stdout] at org.springframework.web.socket.adapter.standard.StandardWebSocketSession.getPrincipal(StandardWebSocketSession.java:123) [stdout] at org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.getPrincipal(WebSocketServerSockJsSession.java:73) [stdout] at org.springframework.web.socket.messaging.StompSubProtocolHandler.afterSessionEnded(StompSubProtocolHandler.java:364) [stdout] at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:352) [stdout] at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:347) [stdout] at org.springframework.web.socket.handler.WebSocketHandlerDecorator.afterConnectionClosed(WebSocketHandlerDecorator.java:85) [stdout] at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.afterConnectionClosed(LoggingWebSocketHandlerDecorator.java:71) [stdout] at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.afterConnectionClosed(ExceptionWebSocketHandlerDecorator.java:89) [stdout] at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.close(AbstractSockJsSession.java:289) [stdout] at org.springframework.web.socket.handler.WebSocketSessionDecorator.close(WebSocketSessionDecorator.java:158) [stdout] at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:287) [stdout] at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:306) [stdout] at org.springframework.messaging.support.ExecutorSubscribableChannel$1.run(ExecutorSubscribableChannel.java:70) [stdout] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [stdout] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [stdout] at java.lang.Thread.run(Thread.java:744) {code} We are using tomcat.

    Spring JIRA | 2 years ago | Prashant Deva
    java.lang.IllegalStateException: The WebSocket session has been closed and no method (apart from close()) may be called on a closed session

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      The WebSocket session has been closed and no method (apart from close()) may be called on a closed session

      at org.apache.tomcat.websocket.WsSession.checkState()
    2. Tomcat WS
      WsSession.getUserPrincipal
      1. org.apache.tomcat.websocket.WsSession.checkState(WsSession.java:652)
      2. org.apache.tomcat.websocket.WsSession.getUserPrincipal(WsSession.java:581)
      2 frames
    3. Spring WebSocket
      SubProtocolWebSocketHandler.afterConnectionClosed
      1. org.springframework.web.socket.adapter.standard.StandardWebSocketSession.getPrincipal(StandardWebSocketSession.java:123)
      2. org.springframework.web.socket.sockjs.transport.session.WebSocketServerSockJsSession.getPrincipal(WebSocketServerSockJsSession.java:73)
      3. org.springframework.web.socket.messaging.StompSubProtocolHandler.afterSessionEnded(StompSubProtocolHandler.java:364)
      4. org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.clearSession(SubProtocolWebSocketHandler.java:352)
      5. org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.afterConnectionClosed(SubProtocolWebSocketHandler.java:347)
      5 frames