Repository navigation
fix(terminal): finalize sessions abandoned mid-handshake so slots aren't leaked - #579
Merged
Hydralerne merged 2 commits intoSep 16, 2026
Conversation
…n't leaked A browser refresh/close during WS open lands in onClose while onOpen is still awaiting the SSH channel and audit-row insert. teardown then ran with no sessionId, marked the connection ended, and onOpen resumed to register a session nobody owns: the idle/cap timeout's teardown became a no-op, leaving the terminal_sessions row open forever. Since the handshake cap counts DB rows with endedAt IS NULL, each abandoned open permanently burned a per-user slot until a restart's closeAllActive() sweep (oblien#426). teardown now defers to onOpen while no session is registered (leaving state.closed set as the abort signal), and onOpen aborts after registration when the WS is already gone: unregistering and finalizing the row instead of wiring a dead connection. Park/resume after "ready" is unchanged. Same-shape fix in the service-terminal controller. New regression test drives the real handler bundle with onClose landing mid-openShell: fails before (in-memory + DB counts stay 1), passes after; a sibling test pins that post-ready disconnects still park.
Farahat612
force-pushed
the
fix/426-terminal-session-leak
branch
from
August 16, 2026 11:43
d965339 to
313c87e
Compare
Hydralerne
changed the base branch from
main
to
feat/bugfix-batch-2026-09-16
September 16, 2026 01:01
This was referenced Sep 16, 2026
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.
A browser disconnect while the PTY or audit insert was pending could register an orphan terminal session afterward, leaving its audit row and user slot active indefinitely. Server and service terminals now finish teardown after the asynchronous open resolves, while ready sessions retain park/resume behavior.
Adapted the original contributor fix to the current platform imports for #892. The ownership audit also found service runtimes leaked on rejected session caps or failed container/count lookups; those now release in finally blocks. Unaudited sessions use UUIDs so simultaneous opens cannot overwrite one another’s registry entries.
Validation: 15 behavior tests drive the actual handlers and registries across both terminal types. Eleven fail on main; all pass after the fix, covering shell/audit interleavings, failed opens/inserts, transient ID collisions and rejected service handshakes. Existing teardown tests also pass: 21 total across three files. API TypeScript passes.
Fixes #426 when #892 merges into main.