fix(sse): fix memory leaks in SSE stream cleanup and add memory telemetry#3378
fix(sse): fix memory leaks in SSE stream cleanup and add memory telemetry#3378waleedlatif1 wants to merge 6 commits intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
e7dec5f to
cf2a497
Compare
|
@cursor review |
|
@greptile |
Greptile SummaryFixed critical memory leaks in SSE stream handling by adding missing Key fixes:
Note: Workflow execute Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Client connects to SSE endpoint] --> B[start: incrementSSEConnections]
B --> C[Create intervals/subscriptions]
C --> D[Stream data to client]
D --> E{Disconnect or cancel?}
E -->|Client abort signal| F[abort listener with once: true]
E -->|Stream cancel called| G[cancel handler]
F --> H[cleanup function]
G --> H
H --> I{Already cleaned?}
I -->|Yes| J[Return early]
I -->|No| K[Set cleaned/closed flag]
K --> L[Clear intervals]
L --> M[Unsubscribe from pub/sub]
M --> N[decrementSSEConnections]
N --> O[Close controller]
P[Memory Telemetry 60s] --> Q[Log heap/RSS stats]
Q --> R[Log SSE connection counts]
R --> S[Log active resources]
S --> P
T[Redis failure] --> U[Events accumulate in pending array]
U --> V{pending.length > cap?}
V -->|Yes| W[Drop oldest events]
V -->|No| X[Keep accumulating]
W --> Y[Log warning]
Last reviewed commit: 96fea68 |
cf2a497 to
2b37d5b
Compare
2b37d5b to
979cae7
Compare
|
@cursor review |
|
@greptile |
…and a2a-message endpoints
Additional Comments (1)
Any events that Since One approach is to not call |
…ween start() and cancel()
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| incrementSSEConnections('wand') | ||
| const reader = response.body?.getReader() | ||
| if (!reader) { | ||
| decrementSSEConnections('wand') |
There was a problem hiding this comment.
Wand early-return decrements without setting guard flag
Low Severity
The early-return path when reader is falsy calls decrementSSEConnections('wand') without setting wandStreamClosed = true. Every other decrement site in this stream (the finally block and the cancel() handler) guards the decrement with the wandStreamClosed flag, but this path is the sole exception. While controller.close() on the next line typically prevents cancel() from firing, the unguarded decrement is inconsistent with the pattern established everywhere else in this PR and creates a subtle maintenance hazard.


Summary
cancel()handler — leaked intervals and pub/sub subscribers on disconnectcancel()not aborting execution — workflows continued running after client disconnect{ once: true }— listener closures held until GCType of Change
Testing
bunx tsc --noEmit)bunx vitest run)bun run lint)Checklist