Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SockJs heartbeat causes deadlock with XHR polling [SPR-14833] #19399

spring-projects-issues opened this issue Oct 21, 2016 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Oct 21, 2016

Grégory Coutant opened SPR-14833 and commented

When using XHR polling as a transport for SockJs, a deadlock can occur when one thread is sending a message at the same time the heartbeat run.

Stack from thread sending a message :

at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.cancelHeartbeat( 
- waiting to lock [0x00000000820ce450] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession.sendMessageInternal( 
- locked [0x00000000820cfce0] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessage(

Heartbeat task :

at org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession.resetRequest( 
- waiting to lock [0x00000000820cfce0] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession.writeFrame( 
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendHeartbeat( 
- locked [0x00000000820ce450] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession$ 
- locked [0x00000000820ce450] (a java.lang.Object)

Looking at the code, there seem to be two locks : heartbeatLock in AbstractSockJsSession and responseLock in AbstractHttpSockJsSession. When calling sendMessage(), the lock order is responseLock then heartbeatLock. For the HeartbeatTask, the lock order is heartbeatLock then responseLock.

Affects: 4.2.8, 4.3.3

Issue Links:

  • #19484 AbstractSockJsSession deadlock when tomcat WsSession is closing

Referenced from: commits 72e1f7e, 1c80d2a, 4ce0e6b

Backported to: 4.2.9

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 27, 2016

Juergen Hoeller commented

Good point: We're using a shared response lock for all interactions of a session now. To be backported to 4.3.4 and 4.2.9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants