im using Stomp over SockJS and Spring websockets as backend. Occasionally Im having problems after my stomp client reconnect (wifi loss, server down, other). The connection is perfectly restored but passed few seconds i can see in browser network how SockJS client try and try send xhr-streaming with the old session id. The backend responde with close frame c[1000, "Go Away!"] The application its still work but this problem load the CPU and slow the application.
I could play turning off and starting the server several times (Not always happen). I cant understand how SockJS once reconnected ( We destroy and create the Sockjs instance from 0 ) send xhr-streaming requests with the id of the old session ( Maintains the pre-reconnection id session? memory leak? ). I'd like to keep it Sockjs not any state after reconnection and always starting from scratch.
Backend log:
2016-05-02 21:45:01.943 DEBUG [http-nio-8090-exec-7] o.s.w.s.s.t.h.XhrStreamingTransportHandler - Connection already closed (but not removed yet) for XhrStreamingSockJsSession[id=ypsjtids] Client log:
(New Sessión Id -> h2pystok, Old session Id -> ypsjtids)
<<< PONG browser.js:120 sockjs-client:buffered-sender send +45ms "\n" browser.js:120 sockjs-client:buffered-sender sendSchedule +0ms 1 browser.js:120 sockjs-client:ajax-based create ajax sender +2ms http://localhost/eess-services/stomp/355/h2pystok ["\n"] browser.js:120 sockjs-client:browser:xhr POST +0ms http://localhost/eess-services/stomp/355/h2pystok/xhr_send ws.js:216 >>> PING browser.js:120 sockjs-client:browser:xhr withCredentials +2ms browser.js:120 sockjs-client:browser:xhr readyState +18ms 4 browser.js:120 sockjs-client:browser:xhr status +1ms 200 browser.js:120 sockjs-client:browser:xhr finish +0ms 200 hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh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hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh browser.js:120 sockjs-client:receiver:xhr _chunkHandler +0ms 200 browser.js:120 sockjs-client:receiver:xhr close +0ms network browser.js:120 sockjs-client:polling close +1ms null network undefined browser.js:120 sockjs-client:polling _scheduleReceiver +0ms browser.js:120 sockjs-client:receiver:xhr http://localhost/eess- services/stomp/266/ypsjtids/xhr_streaming +0ms browser.js:120 sockjs-client:browser:xhr POST +1ms http://localhost/eess-services/stomp/266/ypsjtids/xhr_streaming There is a issue in github: https://github.com/sockjs/sockjs-client/issues/308
I have this problem in production :( Regards.
EDIT:
I found where is the possible error. In polling.js i have see a special treatment when the close reason is 'network'. When is network again call the function _scheduleReceiver(). When we reconnect the infinite loop occurs. I dont know what is the reason for this treatment but I could try this deleting the special treatment of 'network' and everything works correctly. @skozin Can you try?
if (!self.pollIsClosing) { if (reason === 'network') { self._scheduleReceiver(); } else { self.emit('close', code || 1006, reason); self.removeAllListeners(); } }
the workaround is:
if (!self.pollIsClosing) { self.emit('close', code || 1006, reason); self.removeAllListeners(); }
