Skip to content

fix(ws): TOCTOU race in close_on_disconnect - #77535

Closed
eaglezzz0522-cloud wants to merge 1 commit into
NousResearch:mainfrom
eaglezzz0522-cloud:fix/77192-ws-toctou-race
Closed

fix(ws): TOCTOU race in close_on_disconnect#77535
eaglezzz0522-cloud wants to merge 1 commit into
NousResearch:mainfrom
eaglezzz0522-cloud:fix/77192-ws-toctou-race

Conversation

@eaglezzz0522-cloud

Copy link
Copy Markdown

Summary

_close_sessions_for_transport() now snapshots session IDs outside _sessions_lock, then re-validates each session under _session_resume_lock -> _sessions_lock before acting.

Prevents RuntimeError from mutating _sessions dict during iteration; reconnecting session is never silently closed or detached.

Related

Closes #77192

Validation

  • Python syntax check passed
  • Clean rebase on current main (fe6330d)

_close_sessions_for_transport() now snapshots session IDs outside
_sessions_lock, then re-validates each session under _session_resume_lock
-> _sessions_lock before acting.

Prevents RuntimeError from mutating _sessions dict during iteration;
reconnecting session is never silently closed or detached.

Closes NousResearch#77192
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state needs-decision Awaiting maintainer decision before any implementation labels Aug 3, 2026
@eaglezzz0522-cloud

Copy link
Copy Markdown
Author

Closing this in favor of #77129, which implements the same transport-ownership revalidation + adds a deterministic regression test for the exact disconnect/reconnect interleaving. The test coverage in #77129 makes it the better fix — thanks @GottZ for the thorough triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/tui Terminal UI (ui-tui/ + tui_gateway/) needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WS disconnect/reconnect TOCTOU fix exists only on an unmerged branch, missing from main (RAH-06)

2 participants