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

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

Comments

@spring-projects-issues
Copy link
Collaborator

@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(AbstractSockJsSession.java:280) 
- waiting to lock [0x00000000820ce450] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession.sendMessageInternal(AbstractHttpSockJsSession.java:301) 
- locked [0x00000000820cfce0] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessage(AbstractSockJsSession.java:166)

Heartbeat task :

at org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession.resetRequest(AbstractHttpSockJsSession.java:334) 
- waiting to lock [0x00000000820cfce0] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.PollingSockJsSession.writeFrame(PollingSockJsSession.java:83) 
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendHeartbeat(AbstractSockJsSession.java:255) 
- locked [0x00000000820ce450] (a java.lang.Object) 
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession$HeartbeatTask.run(AbstractSockJsSession.java:451) 
- 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

@spring-projects-issues
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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants