0

I use Spring Websocket ( exactly this example Template for my appl ) and somethimes I get this exception at bottom if I invoce disconnect at client:

$scope.$on('$destroy', function() { // invoked if page is leaved 
        if (vm.stompClient != null) {
            vm.stompClient.unsubscribe();
            vm.stompClient.disconnect(function() {
                console.log("Disconnected in chat.controller.js#destroy");
            });
        }
    });

does anyone know what I can do in order to prevent this exception. It does not have any impact to the function - all is still working but it is not clean code and therefor I would fix this issue - Thanks for your help!

java.lang.IllegalStateException: Cannot send a message when session is closed at org.springframework.util.Assert.state(Assert.java:385) at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessage(AbstractSockJsSession.java:159) at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.tryFlushMessageBuffer(ConcurrentWebSocketSessionDecorator.java:126) at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sendMessage(ConcurrentWebSocketSessionDecorator.java:99) at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:368) at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:337) at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:135) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

[EDIT]

I also have found this two log entries:

2015-11-08 07:47:53.642 DEBUG 13452 --- [io-8080-exec-10] s.w.s.h.LoggingWebSocketHandlerDecorator : WebSocketServerSockJsSession[id=kludit93] closed with CloseStatus[code=1000, reason=null] 2015-11-08 07:47:53.643 DEBUG 13452 --- [io-8080-exec-10] o.s.w.s.m.SubProtocolWebSocketHandler : Clearing session kludit93 2015-11-08 07:47:53.646 DEBUG 13452 --- [tboundChannel-4] o.s.w.s.m.SubProtocolWebSocketHandler : No session for GenericMessage [payload=byte[0], headers={simpMessageType=DISCONNECT_ACK, simpSessionId=kludit93}] 2015-11-08 07:47:53.659 DEBUG 13452 --- [tboundChannel-3] o.s.w.s.m.StompSubProtocolHandler : Failed to send WebSocket message to client in session kludit93.

So this means to me that first the session is closed and than it is tried to send something over this closed session to the client. Is there any possibility to prevent this behaviour? Thanks!

quma
  • 5,233
  • 26
  • 80
  • 146

0 Answers0