fix(socketio): don't kick authenticated duplicate-author sessions (#7656)#7678
Open
JohnMcLear wants to merge 2 commits intodevelopfrom
Open
fix(socketio): don't kick authenticated duplicate-author sessions (#7656)#7678JohnMcLear wants to merge 2 commits intodevelopfrom
JohnMcLear wants to merge 2 commits intodevelopfrom
Conversation
) The CLIENT_READY handler kicks any prior socket whose authorID matches the joining socket's, originally as a workaround for stale tabs in the same browser (cookie-derived authorIDs were per-browser, so "same authorID, same pad" reliably meant "page refresh / second tab in this browser"). With stable identities (basic auth, SSO, apikey, getAuthorId hook) the same authorID can legitimately appear across windows or devices, so the kick disconnects real concurrent sessions. Skip the kick when the joining socket has req.session.user set; cookie-only sessions keep the existing behavior so the userdup modal and the xxauto_reconnect path still work.
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Review Summary by QodoSkip duplicate-author kick for authenticated sessions
WalkthroughsDescription• Skip duplicate-author kick for authenticated sessions with stable identities • Preserve kick behavior for cookie-only sessions to maintain userdup modal • Add regression test for cookie-identity duplicate handling • Add test asserting authenticated duplicates are not kicked Diagramflowchart LR
A["CLIENT_READY handler"] --> B{"req.session.user set?"}
B -->|Yes - Authenticated| C["Allow concurrent sessions"]
B -->|No - Cookie only| D["Kick duplicate author"]
C --> E["No userdup disconnect"]
D --> F["Emit userdup message"]
File Changes1. src/node/handler/PadMessageHandler.ts
|
Code Review by Qodo
1.
|
With the duplicate-author kick disabled for authenticated sessions, a single authorID can legitimately span multiple sockets in one pad. handleDisconnect was emitting USER_LEAVE on every socket close, which made clients (whose presence is keyed by authorID) drop the author entirely even when another socket of theirs was still online. Only broadcast USER_LEAVE — and only run the userLeave hook — when the disconnecting socket is the last one in the pad for that author. Adds two backend tests: - authenticated identity: closing one of two same-author sockets does NOT emit USER_LEAVE on the other. - different authors (regression): closing socket A still emits USER_LEAVE for socket B. Action of Qodo review feedback on PR #7678.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
userdupkick inCLIENT_READYwhen the joining socket hasreq.session.userset; cookie-only sessions keep the existing kick + modal soxxauto_reconnectcontinues to work.tests/backend/specs/socketio.ts: regression test for the cookie-identity kick + new test that asserts authenticated duplicates are not kicked.Why
Closes #7656. The kick was added when authorIDs were cookie-derived — "same authorID, same pad" reliably meant "stale tab in the same browser." Stable identities (basic auth, SSO,
apikey, or anygetAuthorIdplugin hook) reuse one authorID across windows and devices, so the kick now disconnects legitimate concurrent sessions. The reporter sees this withAUTHENTICATION_METHOD: "apikey"+REQUIRE_AUTHENTICATION: "true".Test plan
tests/backend/specs/socketio.ts—Duplicate-author handlingdescribe block, both new cases passtests/backend/specs/socketio.ts(35/35 pass)requireAuthentication: true— both stay connected