tbench2 env server: enable idle-session reaper to reclaim leaked slots#1000
Open
Shi-Dong wants to merge 1 commit into
Open
tbench2 env server: enable idle-session reaper to reclaim leaked slots#1000Shi-Dong wants to merge 1 commit into
Shi-Dong wants to merge 1 commit into
Conversation
The /mcp WebSocket handler releases its session slot and Docker container only in a finally block, which runs solely on a clean socket close. Half-open or uncleanly-dropped connections never raise WebSocketDisconnect, so receive_text() blocks forever, finally never runs, and the slot + container leak. Over ~20-24h these accumulate until all MAX_CONCURRENT_ENVS slots are held and new episodes deadlock on CAPACITY_REACHED, requiring a manual env-server reset. create_app was called with a bare max_concurrent_envs, which the core server maps to ConcurrencyConfig(session_timeout=None) -> the idle-session reaper is disabled. Pass an explicit ConcurrencyConfig with session_timeout instead (SESSION_IDLE_TIMEOUT_S env var, default 3600s) so _reap_idle_sessions runs and evicts stale sessions, reclaiming their containers automatically.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The
tbench2_envserver now enables the core idle-session reaper by passing an explicitConcurrencyConfig(max_concurrent_envs=..., session_timeout=...)tocreate_app, instead of the baremax_concurrent_envs=argument. A newSESSION_IDLE_TIMEOUT_Senv var (default3600) controls the reap interval.Why
The
/mcpWebSocket handler releases its session slot and Docker container only in afinallyblock, which runs solely on a clean socket close. Half-open or uncleanly-dropped connections never raiseWebSocketDisconnect, soreceive_text()blocks forever, thefinallynever runs, and the session slot + its Docker container leak.Under sustained load these leaks accumulate over roughly a day until all
MAX_CONCURRENT_ENVSslots are permanently held. New episodes then deadlock onCAPACITY_REACHEDand the only recovery is a manual env-server restart.Passing a bare
max_concurrent_envsmaps toConcurrencyConfig(session_timeout=None)in the core server, which disables_reap_idle_sessions. Supplying an explicitsession_timeoutre-enables the reaper so stale sessions are evicted and their containers reclaimed automatically, without operator intervention.Notes
SESSION_IDLE_TIMEOUT_S=3600preserves existing behavior for short-lived sessions while bounding leaked slots.envs/tbench2_env/server/app.py; no change to the core server or to the on-the-wire protocol.Note
Low Risk
Single-file server bootstrap change with a conservative default timeout; no protocol or core server edits.
Overview
The tbench2_env server now passes an explicit
ConcurrencyConfigtocreate_app(withmax_concurrent_envsandsession_timeout) instead of onlymax_concurrent_envs, which turns on the core idle-session reaper that was previously off whensession_timeoutwas unset.A new
SESSION_IDLE_TIMEOUT_Senv var (default 3600) sets how long a session can sit idle before it is reaped so its WebSocket slot and Docker container are released. That targets leaks from half-open/mcpWebSocket connections that never hit a clean disconnect, which could otherwise hold allMAX_CONCURRENT_ENVSslots until a manual restart.Reviewed by Cursor Bugbot for commit adc5d44. Bugbot is set up for automated code reviews on this repo. Configure here.