Skip to content

fix: clean up long-poll listener and timer on client disconnect - #305

Open
birme wants to merge 1 commit into
mainfrom
bug-fixer/291-longpoll-listener-cleanup
Open

fix: clean up long-poll listener and timer on client disconnect#305
birme wants to merge 1 commit into
mainfrom
bug-fixer/291-longpoll-listener-cleanup

Conversation

@birme

@birme birme commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a request.raw.on('close', ...) cleanup handler to the /production/:productionId/line/:lineId/participants long-poll endpoint so the transient users:change listener and its 25s setTimeout are released immediately when a client disconnects mid-poll, rather than lingering until the timeout fires.
  • Route all three exit paths (users:change fires, timeout expires, client closes) through a single cleanup() guarded by a settled boolean, guaranteeing symmetric listener/timer removal and preventing double-resolve.
  • Call productionManager.setMaxListeners(0) in the ProductionManager constructor to suppress spurious MaxListenersExceededWarning under >10 concurrent pollers.

Test plan

  • Tests pass (npm test) — 243/243
  • TypeScript compiles (npm run typecheck)
  • Lint clean (npm run lint) — 0 errors
  • Long-poll test asserts off('users:change', ...) is called on the change exit path

Closes #291

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

Register a request close handler on the participants long-poll endpoint
so the transient 'users:change' listener and its 25s timeout are released
when a client disconnects mid-poll, instead of lingering until timeout.
A guard boolean ensures cleanup runs exactly once across the change,
timeout, and close exit paths so the promise never resolves twice.

Also disable maxListeners on the ProductionManager EventEmitter to avoid
spurious MaxListenersExceededWarning under >10 concurrent pollers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Long-poll endpoint accumulates EventEmitter listeners without cleanup on client disconnect

1 participant