-
Notifications
You must be signed in to change notification settings - Fork 14.7k
SSE event streams leak memory on client disconnect #15645
Copy link
Copy link
Open
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)Anything pertaining to core functionality of the application (opencode server stuff)