Skip to content

SSE event streams leak memory on client disconnect #15645

@brendandebeasi

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

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