Skip to content

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

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

Closed
spring-projects-issues opened this issue Oct 21, 2016 · 1 comment
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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:

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

Backported to: 4.2.9

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3.4 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants