Skip to content

fix(dashboard): SSE backpressure + liveness — stop unbounded write buffering that OOM-crashed the dashboard after ~39h - #664

Merged
HenryLach merged 1 commit into
mainfrom
fix/dashboard-sse-backpressure
Sep 18, 2026
Merged

HenryLach merged 1 commit into
mainfrom
fix/dashboard-sse-backpressure

Conversation

@HenryLach

Copy link
Copy Markdown
Owner

A stalled SSE client (background-throttled tab, sleeping laptop, half-open
TCP) never fires 'close', and res.write() never throws — it buffers. Every
2 s broadcast (~60 KB for a penster batch) accumulated in that buffer until
V8's 4 GB heap limit: 140,714,810 ms uptime / 2000 ms ≈ 70k ticks ≈ 60 KB
per tick, matching the crash exactly.

  • writeToSseClients(): skip a client with writableNeedDrain or a write
    buffer over 2 MB; drop (destroy + remove) after 15 consecutive stalled
    ticks (~30 s); log drops. Extracted as a pure function for tests.
  • handleSSE(): ': ping' comment every 15 s and a 90 s socket idle timeout so
    a dead peer surfaces as error/close; remove the client on close/error from
    both req and res; clear the ping timer on removal.

Test: dashboard-sse-backpressure.test.ts (7) incl. the 39-hour scenario —
a permanently stalled client is dropped holding < ~2.1 MB. 4142 pass.

…ffering that OOM-crashed the dashboard after ~39h

A stalled SSE client (background-throttled tab, sleeping laptop, half-open
TCP) never fires 'close', and res.write() never throws — it buffers. Every
2 s broadcast (~60 KB for a penster batch) accumulated in that buffer until
V8's 4 GB heap limit: 140,714,810 ms uptime / 2000 ms ≈ 70k ticks ≈ 60 KB
per tick, matching the crash exactly.

- writeToSseClients(): skip a client with writableNeedDrain or a write
  buffer over 2 MB; drop (destroy + remove) after 15 consecutive stalled
  ticks (~30 s); log drops. Extracted as a pure function for tests.
- handleSSE(): ': ping' comment every 15 s and a 90 s socket idle timeout so
  a dead peer surfaces as error/close; remove the client on close/error from
  both req and res; clear the ping timer on removal.

Test: dashboard-sse-backpressure.test.ts (7) incl. the 39-hour scenario —
a permanently stalled client is dropped holding < ~2.1 MB. 4142 pass.
@HenryLach
HenryLach merged commit aff21b3 into main Sep 18, 2026
1 check passed
@HenryLach
HenryLach deleted the fix/dashboard-sse-backpressure branch September 18, 2026 16:19
HenryLach added a commit that referenced this pull request Sep 18, 2026
fix(dashboard): SSE stall eviction is elapsed-time based; one idempotent teardown for every exit path (Sage review of #664)
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.

1 participant