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
harness: cap concurrent re-attach streams, so attach readers cannot exhaust Redis connections (follow-up to #471) #478
Follow-up from #471 (detachable turns). The final branch review deferred this by ruling.
Goal
One client, or a few, cannot exhaust the harness's Redis connections by opening re-attach streams.
Current state
TurnRegistry.attach() (harness/src/turn-registry.ts) gives every GET /v1/turn?sessionId= its own duplicated Redis connection (client.duplicate()). This is necessary because XREAD BLOCK would otherwise stall every other command on the shared client.
The connection is released when the stream ends, the client disconnects, or close() runs. Nothing caps how many are open at once. There is no limit per process, per session, or per subject.
An authenticated client holding a valid session token can open attach streams in a loop. Each one holds a Redis connection until it ends, so the client can push Redis toward maxclients and starve everything else that shares it: sessions, leases, the control plane.
mocactl itself opens one attach per resume, and re-attaches at most 5 times after a dropped stream. Normal use is far below any sensible cap.
Scope
Cap concurrent attach readers per process, for example SH_TURN_ATTACH_MAX with a default sized against the worker's Redis budget. Past the cap, answer 503 {"error":"attach_unavailable"} with Retry-After. mocactl already retries on 503s that carry Retry-After.
Cap concurrent attaches per session at a small number (2–4), so one session cannot use the whole process budget. A further attach for that session gets 429 or 409; pick one and document it.
Optional: serve several attaches of the same turn from one reader in the process (fan-out). That would make the per-session cap mostly moot.
Expose the current attach-reader count in the worker's advisory stats message, so /metrics can show it.
Acceptance
With the cap at N, the (N+1)th concurrent attach in a process gets the documented status, and it recovers once one ends.
The per-session cap holds across attaches to the same session.
A test shows reader connections return to zero after streams end, abort, or close().
deploy/compose README, vm env example, and k8s base document the new settings.
Activity