'Spring Websockets via STOMP - Client crash and SessionDisconnectEvent
I'm implementing a Spring web application using Websocket, the sub protocol STOMP as well as SockJs for Fallback.
Currently I want to implement some kind of session management, meaning that I want to maintain a list at the server of the clients that are connected to my Spring App via Websocket.
My current naive approach based on https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#websocket-stomp-appplication-context-events is, that I implemented 2 event handlers. One for SessionConnectedEvent and one for SessionDisconnectEvent. When a SessionConnectedEvent arrives, I add a session to my list, when a SessionDisconnectEvent arrives, I delete that session from my list.
What I'm wondering is: Does the SessionDisconnectEvent also arrive when the client crashed and didn't have time to inform the server that it is closing the connection? E.g. if the underlying operating system of the client has a malfunction.
I tried to simulate this using the Task Manager of Windows and tried to shut down the browser. But I can still see that the SessionDisconnectEvent gets fired. This can't be because of the heartbeat, since - as far as I know - the ping pong mechanism only fires every 25 seconds by default in Spring Websockets. The SessionDisconnectEvent fired immediately after I closed the browser via the task manager.
Does my test mean that the server can also detect client crashes?
Solution 1:[1]
Okay, I think I can answer it myself. I tested it with my colleague. He connected via Websocket with the WebApp, and then he turned of the Wifi connection. It took some more seconds, but after a short while Spring also recognized the lost connection and fired the event. So everything works like a charm :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Walnussbär |
