Matchmaking returns "Session not found" (401) for a valid JWT after a transient MQTT disconnect, with no recovery path
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- typescript
- 领域
- api, authentication, backend
调研方向
从 src/features/matchmaking/matchmaking.route.ts 中严格的 getSession 查找开始,然后将其与 src/features/auth/auth.service.ts 中的 ensureSession 进行比较。重现 issue 中描述的缺少 session 的请求,并验证有效的 JWT 可以恢复由数据库支持的 session,而不是收到 Session not found (401)。
由索引模型根据 Issue 内容生成。
描述
Matchmaking returns "Session not found" (401) for a player with a valid JWT, with no recovery path
Summary
A player who is correctly authenticated (valid JWT) can be permanently locked out of matchmaking with Session not found (401) after a single transient MQTT disconnect. Retrying does not help, because nothing recreates the in-memory session and the still-valid JWT means the client never re-authenticates. The only workaround is a full client restart.
Root cause
The in-memory session and the stateless JWT have decoupled lifetimes, and the matchmaking route is the only flow that requires the session strictly instead of self-healing.
-
Sessions are in-memory only.
src/state/index.ts—export const sessions = new Map<string, PlayerSession>(). No persistence, no rehydration on startup. -
JWT auth never checks for a session.
src/middleware/authenticate.tsonly runsverifyJwt(token)and setsreq.player. A valid token passes even when the session is gone. -
A non-lobby disconnect reaps the session immediately.
src/features/emqx/emqx.route.ts:async function releasePlayerLobbyOrSession(clientid) { const session = getSession(clientid) if (!session) return leaveAllQueues(clientid) if (session.lobbyCode) { await startGracePeriod(clientid) // lobby members get a grace period } else { removeSession(clientid) // everyone else is removed on the spot } }The MQTT
clientidis theplayerId(the client sendsplayer_idas the MQTT client id), sogetSession(clientid)/removeSession(clientid)resolve the real session. A player who is matchmaking — and therefore not yet in a lobby — has their session deleted the instant EMQX reportsclient.disconnected. -
Matchmaking requires the session strictly.
src/features/matchmaking/matchmaking.route.ts:const session = getSession(req.player.playerId) if (!session) throw new AppError('Session not found', 401)By contrast, ~5 other endpoints call
ensureSession()(src/features/auth/auth.service.ts), which rebuilds the session from the DB when it's missing. Matchmaking is the asymmetric one that does not self-heal.
Reproduction
- Authenticate (Steam) — session created, MQTT connected.
- Drop the MQTT connection briefly (ordinary network blip). The client default is
reconnect = false, so it does not auto-reconnect. - EMQX fires
client.disconnected; since the player isn't in a lobby, the server callsremoveSessionimmediately. - Click matchmake →
POST /api/matchmaking/queuewith the still-valid JWT →getSessionreturns nothing →Session not found(401). - Retrying never recovers: the JWT is still valid, so the client doesn't re-auth, and nothing else recreates the session.
Impact
A single transient disconnect strands an authenticated player. From the user's side it looks like matchmaking is simply broken; the only fix they have is to fully quit and relaunch the game (which forces a fresh /auth and recreates the session).
Suggested fixes (in order of smallest blast radius)
- Make matchmaking self-heal like the other routes — use
ensureSession(req.player.playerId)instead of strictgetSession. A DB-backed (Steam-authed) player would transparently get their session rebuilt instead of a 401. This is the minimal, consistent fix. - Don't immediately reap non-lobby sessions on disconnect — give them the same grace period lobby members get, so a brief blip doesn't destroy the session.
- (Client-side, optional) Treat a
401 Session not foundas "re-authenticate, then retry" rather than surfacing it as a terminal error.
Notes / unverified
The mechanism above is confirmed against the code end-to-end (in-memory map, stateless JWT, immediate non-lobby reap, strict matchmaking lookup, clientid == playerId). What is not independently confirmed is that a given user report was caused by this exact path versus another session-loss trigger (e.g. a server restart/redeploy wiping the in-memory map, or a grace-period expiry). All of those funnel into the same end state — valid JWT, no session, strict 401 — so the fixes apply regardless.
- 主要语言
- TypeScript
- 星标
- 13
- 派生
- 21
- 平均合并
- 3 天 16 小时
- 30 天内合并 PR
- 6
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Balatro-Multiplayer/BalatroMultiplayerAPI-Server 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
-
难度 3/5 1-2 天 新手友好度 72/100
-
难度 5/5 一周以上 新手友好度 20/100
查看 Balatro-Multiplayer/BalatroMultiplayerAPI-Server 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
bcgov/bc-wallet-mobile#4761 · 1 条评论 ·
-
external-issue to-triage
难度 2/5 1-3 小时 新手友好度 88/100
-
area-deployment area-integrations triage:bot-seen
难度 2/5 半天 新手友好度 86/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
refactor
难度 2/5 1-3 小时 新手友好度 84/100