rstoyanchev / spring-websocket-portfolio

740 stars 443 forks source link

Stomp over websocket : session gets closed without client sending unsubscribe/disconnect #61

Closed darshanmehta10 closed 8 years ago

darshanmehta10 commented 8 years ago

RabbitMQ : 3.6.0 Spring WebSocket : 4.1.8 Spring boot : 1.2.7

Snippet of client code:

var id = stomp.subscribe('<url>', function(d) {
console.log(messageCount);
messageCount = messageCount + 1;
}, {'auto-delete' : false, 'persistent' : true , 'id' : 'unique_id', 'ack' : 'client'});
}, function(err) {
console.log(err);
debug('error', err, err.stack);
setTimeout(stompConnect, 10);
});

This tries to connect to an existing queue (durable subscription), it gets connected initially, however, after 5 seconds, the connection drops and following gets printed:

Whoops! Lost connection to < url >

Server logs show the following:

for session cyzp3nsn; nested exception is     org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver     message(s) [ACK
message-id:T_unique_id@@session-L9oqyTEyWBN5nFS5VQ_9gw@@1
subscription:unique_id

 ] for session cyzp3nsn: Session closed
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:979)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:808)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:224)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:299)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.springframework.boot.actuate.autoconfigure.MetricsFilter.doFilterInternal(MetricsFilter.java:76)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS     request, uri=http://localhost/cyzp3nsn/xhr_send; nested exception is     org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver     message(s) [ACK
message-id:T_unique_id@@session-L9oqyTEyWBN5nFS5VQ_9gw@@1
subscription:unique_id

 ] for session cyzp3nsn; nested exception is     org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver     message(s) [ACK
message-id:T_unique_id@@session-L9oqyTEyWBN5nFS5VQ_9gw@@1

And then, this gets logged repeatedly:

for session cyzp3nsn: Session closed
at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.delegateMessages(AbstractSockJsSession.java:382)
... 51 common frames omitted

[reactor-tcp-io-3] reactor.net.netty.tcp.NettyTcpClient     : CONNECTED: [id: 0x78ac6290, host => mq]
[reactor-tcp-io-3] reactor.net.netty.tcp.NettyTcpClient     : CLOSED: [id: 0x78ac6290, host => mq]
WARN 9389 --- [qtp120524927-17] o.eclipse.jetty.servlet.ServletHandler   : 

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=http://localhost/717/nxsjuvry/xhr_send; nested exception is org.springframework.web.socket.sockjs.SockJsMessageDeliveryException: Failed to deliver message(s) [ACK
message-id:T_unique_id@@session-_d701SFhsnKQ0SxNuuHE4Q@@1
subscription:unique_id

Client goes into re-connection loop and no message is retrieved. It seems the HTTP Session gets closed even if Websocket connection is active.

I have tried tweaking the following parameters:

com.rabbitmq.client.ConnectionFactory rabbitMqConnectionFactory = new com.rabbitmq.client.ConnectionFactory();
rabbitMqConnectionFactory.setAutomaticRecoveryEnabled(true);
rabbitMqConnectionFactory.setConnectionTimeout(60);

However, session still keeps getting closed. Spring boot (Jetty) needs to keep HTTP Session alive if Websocket session is active.

rstoyanchev commented 8 years ago

This has nothing to do with the sample here.

rstoyanchev commented 8 years ago

I'm not going to answer any further questions here but in case you post elsewhere keep in mind you've too many open questions or inaccuracies in your report:

Client goes into re-connection loop

Re-connection is not built-in so you have to explain what's trying to reconnect and show some evidence if needed.

com.rabbitmq.client.ConnectionFactory

Spring WebSocket does not use the RabbitMQ client so this part seems irrelevant.

Spring boot (Jetty) needs to keep HTTP Session alive if Websocket session is active.

From the stacktrace this looks like a SockJS (HTTP transport) and not an actual WebSocket connection.

Spring boot : 1.2.7

You should upgrade to 1.2.8 at least.