Skip to content

[Backend] SSE broadcast/heartbeat ignore res.write() backpressure - unbounded buffering on slow clients #842

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

sse.service.ts:216 (broadcast) and :92 (sendHeartbeat) call client.res.write(...) and discard the boolean return value. When a consumer cannot drain (slow/stalled socket), Node buffers every event in the socket's writable buffer with no high-water-mark check, no drain wait, and no max-buffer disconnect. Under the documented 10k-connection / 1k-events-sec target a few stalled clients cause unbounded heap growth and OOM. broadcast also has an empty catch that does not prune the failed client (unlike sendHeartbeat).

Acceptance criteria

  • Check the res.write() return value; when false, stop sending to that client until drain or disconnect it after a bounded writableLength threshold
  • On write failure in broadcast(), remove the client (mirror sendHeartbeat)
  • Expose a slow-client-dropped counter for observability
  • Add a test where a client's write() returns false / throws and the client is removed without blocking others

Files to touch

  • backend/src/services/sse.service.ts

Out of scope

  • Switching transport from SSE to WebSocket

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbackendBackend related tasksbugSomething isn't workingcritical

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions