Repository navigation
fix(backend): Phase 2.3 SSE heartbeat leak on disconnect - #666
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 56 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
* fix(backend): guard SSE heartbeat against client disconnect leak * test(backend): expand SSE heartbeat leak coverage * test(backend): add timer cleanup and additional SSE heartbeat tests * test(backend): remove flaky test relying on 30s interval * chore: add NOSONAR comments to exception handlers in SSE heartbeat * test(backend): cover SSE heartbeat exception paths for sonar



Bug
Heartbeat interval on SSE connections leaks when client disconnects mid-send. The
setIntervalkeeps firing and itsres.write(...)throws on a closed socket, producing error spam — and if the interval holds refs to per-client state, memory leaks accumulate.Fix
Wrapped heartbeat scheduling in defensive guards:
const controller = new AbortController()per SSE clientreqemitsclose, callcontroller.abort()andclearInterval(heartbeat)res.writecalls: checkcontroller.signal.aborted || res.writableEnded || res.destroyedbefore writing, skip and return if trueFiles Changed
packages/backend/src/routes/music/stateRoutes.ts: Added AbortController and guards to heartbeat intervalpackages/backend/tests/integration/routes/musicState.test.ts: Added regression test for early disconnectTest Results
Risk
Very low — pure defensive guards added, no behavioral changes. Interval now skips write attempts on dead sockets instead of throwing.