Skip to content

SSE event subscriptions buffer without bound when the consumer stops draining #31923

Closed as duplicate

Description

@MartinCajiao

Description

A client that opens /event or /global/event and stops draining leaks server memory. Each subscription buffers events in an unbounded queue, and the only cleanup is the response fiber ending, which requires a disconnect signal. A TCP connection stuck in CLOSE_WAIT never sends one, so the listener stays registered and the queue grows with every event the server emits.

The megathread has field measurements of this pattern: 24.5GB RSS with zombie CLOSE_WAIT connections, +434MB/30s growth at a stable zombie count (#20695 (comment)).

Two aggravators in current dev:

  • the instance endpoint filters by directory after buffering, so a stalled subscriber accumulates all instances' events
  • the global endpoint buffers through Stream.callback with the same exposure

Reproduction

Open an event endpoint, never read the body, publish events past any reasonable backlog size. The per-connection queue grows monotonically and the response stream never terminates. A deterministic regression test is included in the linked PR.

Version

Current dev. Matches the v1.4.3 behavior reported in the megathread; the Effect migration preserved the pattern (Queue.unbounded per connection in handlers/event.ts).

Part of #20695.

Activity

  1. github-actions commented on Jun 11, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Both issues describe the identical code pattern and memory growth behavior. You may want to reference or close in favor of one of those.

  2. MartinCajiao commented on Jun 11, 2026

    @MartinCajiao
    Author

    Duplicate of #22198 — the duplicate-detection bot is right, that report covers the same root cause with field measurements. Closing this one; the fix PR #31922 now links #22198 directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions