fix(auth): raise per-user JWT cap to 20; quiet WS reconnect race#31
Merged
fix(auth): raise per-user JWT cap to 20; quiet WS reconnect race#31
Conversation
Two related fixes for the per-user concurrent JWT cap: 1. Raise auth.MaxRefreshFamilies (and TokenTracker.MaxTokens) from 5 to 20. With a 15-min access TTL refreshing roughly four times an hour, the old limit pushed a desktop's session off the active list within an hour of normal multi-device use (desktop + phone). 20 leaves headroom without inflating the deny list, and the TTL still bounds the impact of a stolen refresh family. 2. WebSocket clients (listener and admin) no longer call .close() on a socket still in CONNECTING state during a reconnect. Detach the handlers and route the close through onopen instead, suppressing the cosmetic 'WebSocket is closed before the connection is established' browser console warning seen after a token-expiry refresh. Tests updated to derive from auth.MaxRefreshFamilies instead of hard-coded 5. All Go and frontend tests pass.
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.
Symptoms
After yesterday's audio HTTP migration, two related console annoyances surfaced when using OpenScanner from a phone and a desktop simultaneously:
GET /api/calls/:id/audio 401 (Unauthorized)on the desktop after a sibling-device login (mostly fixed in fix(audio): silently retry on 401 from /api/calls/:id/audio #30 with the silent retry, but the 401 itself was a symptom of a tighter root cause).WebSocket connection to 'wss://\u2026/api/admin/ws' failed: WebSocket is closed before the connection is establishedafter the admin WS hits an XPR (token-expired) frame and reconnects.Root cause
The server caps each user at 5 concurrent access JWTs (
auth.MaxRefreshFamilies,TokenTracker.MaxTokens). With access TTL=15 min and a silent refresh ~1 min before expiry, every active browser/tab consumes ~4 token slots per hour. Desktop + phone alone burn through 5 slots in barely over an hour, at which point the desktop's JWT \u2014 and therefore itsos_sessioncookie \u2014 ends up server-side-revoked. The audio 401 retry covered the symptom, but the cap itself was the wrong shape for a multi-device homelab tool.The WS warning is a separate, smaller bug: when the admin client receives
XPRit reconnects viadoConnect(), which closes the existing socket immediately. If that existing socket is still inCONNECTINGstate, Chrome logs the warning. The reconnect itself succeeds, so it's purely cosmetic \u2014 but worth fixing now while the area is fresh.Changes
backend/internal/auth/auth.go:MaxRefreshFamilies5 \u2192 20.NewTokenTrackerdefaults toMaxRefreshFamiliesinstead of a hard-coded 5. Comment explains the rationale (15-min access TTL + multi-device homelab usage).backend/internal/auth/auth_test.go:TestTokenTracker_MaxFiveTokensrenamed and parameterised onauth.MaxRefreshFamiliesso future cap tweaks don't require test edits.frontend/src/services/ws/client.ts+adminClient.ts:doConnectanddisconnectdetach handlers on the previous socket, then either close it directly (if OPEN) or hookonopento a self-close (if CONNECTING). Eliminates the noisy browser warning..github/copilot-instructions.mdand.github/agents/reviewer.agent.md: bump the documented limit from 5 to 20 so future reviewers don't flag the new constant.CHANGELOG.md: two bullets under[Unreleased]Fixed.Verification
go build ./...clean.go test ./internal/auth/... ./internal/handler/routes/...pass;refresh_test.goalready derived fromauth.MaxRefreshFamilies.pnpm exec tsc --noEmitclean.pnpm test --run\u2014 188 / 188 pass.Self-review
Follow-up
The audio 401-retry path (#30) is still the right belt-and-braces handler for unrelated revocations (admin force-logout, etc.) and stays in.