You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tower SSE thundering herd causes ephemeral port exhaustion on localhost #1124
The Tower server SSE endpoint (GET /api/events, port 4100) has a hard client cap of 50 (SSE_MAX_CLIENTS in tower-server.ts). When exceeded, the server evicts the oldest client to make room. The evicted client auto-reconnects, which pushes the count back to the cap, evicting another client — creating a thundering herd loop at up to ~800 connections/second.
Each short-lived TCP connection leaves a socket in TIME_WAIT for ~60 seconds. At peak churn this accumulates 2,900+ TIME_WAIT sockets against 127.0.0.1:4100, consuming ~10% of the ephemeral port range (32768–60999). This causes intermittent EADDRNOTAVAIL / connection-refused errors for all localhost services — not just Tower.
Root Cause Chain
SSE client count exceeds cap (50)
Server evicts oldest client (sseClients.shift() + res.end())
Evicted client reconnects (browser EventSource ~3s, VSCode via backoffDelayMs)
Reconnect pushes count back to cap → another eviction → cascade
Each connection leaves TIME_WAIT socket (~60s TTL)
Ephemeral port pool (28,232 ports) depleted under sustained load
Other localhost services (gRPC, Postgres, Kafka, Redis) fail intermittently
Evidence
Metric
Value
Peak connect rate
49,524 connects/min
TIME_WAIT sockets at diagnosis
2,888 against 127.0.0.1:4100
Port utilization at peak
~10% sustained, higher in bursts
Log file size (2.5 days)
1.18M lines, 774K SSE connect/disconnect
Code Locations
Cap + eviction logic: packages/codev/src/agent-farm/servers/tower-server.ts — addSseClient
Activity
amustafa commentedon Jul 1, 2026
On it! Working on a fix now.
[Bugfix cluesmith#1124] Fix: dashboard SSE client reconnects on 503 r…
[Bugfix cluesmith#1124] Update thread: CMAP Gemini finding addressed
[Bugfix #1124] Fix: SSE thundering herd causing ephemeral port exhaus…