Open ArmanNisch opened 4 years ago
Sessions are an internal construct and not intended to be manipulated outside the library. They automatically unregister post-disconnect after a certain delay. Changing them to persist long-term would break many assumptions and likely cause other issues like socket and memory leaks.
Ok, but what about this scenario: what if a frontend might be waiting for a computationally heavy response form the server, then and for some reason the frontend is disconnected and then reconnected. In this scenario, does the frontend have to make a new session with the server and requested the data again, because the first session has now been destroyed by the socksJS server?
Would there not be a way to retrieve the older session to get the original, computationally heavy, response from the server?
I suggest you have your own session ID that you send through the SockJS channel upon connect. Your initial idea seems fine, but don't use SockJS internals to accomplish it. It should live outside of the library. You may want to look into libraries such as https://github.com/primus/primus that layer on top of real-time transports to provide additional functionality.
I am trying to persist server side sessions, even after the client has disconnected.
I have a standard SockJS client and sockjs-node setup.
The idea is that if a Client connects, then disconnects, and then re-connects to the server; the client should get back the same session from the server on every connection.
To try and achieve this, I am currently generating a random session ID string on the client side then I am passing this ID to the sockJS server.
The problem I am facing is that the Server Returns null when I pass the sessionID to the server to try and retrieve an existing session.
As far as I can see, this is how SockJS implements session persisting: https://github.com/sockjs/sockjs-node/blob/master/lib/session.js
I don't quite understand why I am getting back null, the session should be maintained on the server...?
I am trying to persist server side sessions, even after the client has disconnected.
I have a standard SockJS client and sockjs-node setup.
The idea is that if a Client connects, then disconnects, and then re-connects to the server; the client should get back the same session from the server on every connection.
To try and achieve this, I am currently generating a random session ID string on the client side then I am passing this ID to the sockJS server.
The problem I am facing is that the Server Returns null when I pass the sessionID to the server to try and retrieve an existing session.
As far as I can see, this is how SockJS implements session persisting: https://github.com/sockjs/sockjs-node/blob/master/lib/session.js
I don't quite understand why I am getting back null, the session should be maintained on the server...?
This is how I currently send the ID to the SockJS Server:
This is how I currently am trying to retrieve the same session on the Server: