Closed
Description
William Hoyle opened SPR-14356 and commented
In the following log the heartbeat thread is SockJsScheduler-8
and the client thread is Broadcaster-3
.
There appears to be a race condition between the heartbeat task and the send thread. The send thread attempts to cancel the heartbeat task before sending, but the heartbeat task has already started.
2016-06-13T00:14:22.288Z [TRACE] [] [SockJsScheduler-8] [WebSocketServerSockJsSession] Preparing to write SockJsFrame content='h'
2016-06-13T00:14:22.288Z [TRACE] [] [Broadcaster-3] [UserWebSocket] Session[fair3vq5]: Tx 'h' to user 76042
2016-06-13T00:14:22.288Z [TRACE] [] [SockJsScheduler-8] [WebSocketServerSockJsSession] Writing SockJsFrame content='h'
2016-06-13T00:14:22.288Z [TRACE] [] [Broadcaster-3] [WebSocketServerSockJsSession] Cancelling heartbeat in session fair3vq5
2016-06-13T00:14:22.288Z [TRACE] [] [SockJsScheduler-8] [NativeWebSocketSession] Sending TextMessage payload=[h], byteCount=1, last=true], StandardWebSocketSession[id=83, uri=/ajax/watch/websocket/029/fair3vq5/websocket]
2016-06-13T00:14:22.288Z [TRACE] [] [Broadcaster-3] [WebSocketServerSockJsSession] Preparing to write SockJsFrame content='a["h"]'
2016-06-13T00:14:22.288Z [TRACE] [] [Broadcaster-3] [WebSocketServerSockJsSession] Writing SockJsFrame content='a["h"]'
2016-06-13T00:14:22.288Z [TRACE] [] [Broadcaster-3] [NativeWebSocketSession] Sending TextMessage payload=[a["h"]], byteCount=6, last=true], StandardWebSocketSession[id=83, uri=/ajax/watch/websocket/029/fair3vq5/websocket]
2016-06-13T00:14:22.289Z [TRACE] [] [SockJsScheduler-8] [WebSocketServerSockJsSession] Scheduled heartbeat in session fair3vq5
2016-06-13T00:14:22.289Z [DEBUG] [] [Broadcaster-3] [WebSocketServerSockJsSession] Terminating connection after failure to send message to client
java.lang.IllegalStateException: The remote endpoint was in state [TEXT_PARTIAL_WRITING] which is an invalid state for called method
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.checkState(WsRemoteEndpointImplBase.java:1064)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$StateMachine.textPartialStart(WsRemoteEndpointImplBase.java:1022)
at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialString(WsRemoteEndpointImplBase.java:184)
at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:49)
Affects: 4.2.5
Issue Links:
- Memory leak on STOMP broker connections that fail before heartbeats start [SPR-14266] #18838 Memory leak on STOMP broker connections that fail before heartbeats start
- SockJS heartbeat is causing application send Message to fail similar to (SPR-14356) [SPR-14564] #19133 SockJS heartbeat is causing application send Message to fail similar to (SPR-14356)
Referenced from: commits 5075dd4, 91387a5, 4c87167, 16879a2, ba885f3
Backported to: 4.2.7