Not able to retrieve the same session (sessionID) in SockJS (Websocket) NodeJS Server
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, nodejs
- Domain
- backend
Research direction
Read lib/session.js first, then trace how the client sessionId callback is handled by the SockJS server and how SockJSSession.bySessionId(sessionId) looks up sessions. Reproduce the disconnect and reconnect flow using the shown client and server snippets. Done means the session lookup behavior is explained and a focused regression test or documentation change captures the expected result.
Written by the indexing model from the issue text.
Description
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:
// (1) How I currently send the ID to the SockJS Server.
const socket = SockJS("${apiServerURL}/socket/auth/login", null, {
sessionId: () => {
// (2) Check if a session ID already exhists
let sessionId = localStorage.getItem("sockjsSessionId");
if(sessionId === null || sessionId === undefined) {
// (3) If Session ID does not exist, create a random ID.
sessionId = getRandomStringWithLength(8);
localStorage.setItem("sockjsSessionId", sessionId);
}
// (4) Pass session id to SockJS Server
return sessionId;
}
})
This is how I currently am trying to retrieve the same session on the Server:
if (sessionId !== null && typeof sessionId !== "undefined") {
const socketSession: SockJSSession | null = SockJSSession.bySessionId(sessionId);
console.log("found sockjs session connection", socketSession);
if (socketSession !== null) {
socketSession.connection.write(JSON.stringify(response));
}
}
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sockjs/sockjs-node
-
CVE issues (uuid)Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
sockjs/sockjs-node#329 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sockjs/sockjs-node#316 · 14 comments · 26 reactions ·
-
Is prefix a must?Open
Difficulty 3/5 1-2 days Newbie friendliness 30/100
sockjs/sockjs-node#311 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
sockjs/sockjs-node#304 · 2 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
sockjs/sockjs-node#301 ·
All issues in sockjs/sockjs-node
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
daisy/a11y-meta-viewer#18 ·
-
good first issue status: needs triaging type: bug version: 2.0
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
medusajs/medusa#17094 · 2 comments ·
Maintainers usually reply within 1 day
-
browser: chrome package: @carbon/react package: styles
Difficulty 1/5 Under an hour Newbie friendliness 92/100
carbon-design-system/carbon#23567 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
clerk/javascript#10033 ·
Maintainers usually reply within 1 day
-
bug client p1
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vercel/eve#4173 · 2 comments ·
Maintainers usually reply within 1 day