Skip to content

SSE event streams leak memory on client disconnect #15645

Closed

Description

@brendandebeasi

Description

SSE event streams in server.ts and routes/global.ts leak memory when clients disconnect. The stream.writeSSE() calls are fire-and-forget, so write failures to dead connections go undetected. Bus listeners and heartbeat intervals keep accumulating across reconnects.

In long-running sessions with many reconnects, this causes steady memory growth (~15+ MB observed) from orphaned listeners and intervals that are never cleaned up.

Steps to reproduce

  1. Start the OpenCode server (bun dev serve)
  2. Open multiple SSE connections (e.g. via browser tabs or curl)
  3. Close the connections abruptly (kill the client without a clean close)
  4. Repeat steps 2-3 many times
  5. Observe that Bus subscription counts grow and memory usage increases steadily

OpenCode version

Latest dev branch

Operating System

macOS (reproduced), likely affects all platforms

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 2, 2026
  2. github-actions commented on Mar 2, 2026

    @github-actions
    Contributor

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

    If your issue is already covered by one of those, please consider adding details there instead.

  3. abrekhov commented on Mar 20, 2026

    @abrekhov

    +1 — confirmed this is the root cause of the 60GB+ OOM crashes reported in #17908. Added detailed diagnostics and root-cause trace there.

  4. thdxr commented on Apr 2, 2026

    @thdxr
    Member

    Closing in favor of #20695 where we're collecting all memory-related problems. Please follow that issue for updates.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions