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
- Start the OpenCode server (
bun dev serve)
- Open multiple SSE connections (e.g. via browser tabs or curl)
- Close the connections abruptly (kill the client without a clean close)
- Repeat steps 2-3 many times
- Observe that Bus subscription counts grow and memory usage increases steadily
OpenCode version
Latest dev branch
Operating System
macOS (reproduced), likely affects all platforms
Description
SSE event streams in
server.tsandroutes/global.tsleak memory when clients disconnect. Thestream.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
bun dev serve)OpenCode version
Latest dev branch
Operating System
macOS (reproduced), likely affects all platforms