Skip to content

fix(terminal): finalize sessions abandoned mid-handshake so slots aren't leaked - #579

Merged
Hydralerne merged 2 commits into
oblien:feat/bugfix-batch-2026-09-16from
Farahat612:fix/426-terminal-session-leak
Sep 16, 2026
Merged

Hydralerne merged 2 commits into
oblien:feat/bugfix-batch-2026-09-16from
Farahat612:fix/426-terminal-session-leak

Conversation

@Farahat612

@Farahat612 Farahat612 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

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.

…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
Farahat612 force-pushed the fix/426-terminal-session-leak branch from d965339 to 313c87e Compare August 16, 2026 11:43
@Hydralerne
Hydralerne changed the base branch from main to feat/bugfix-batch-2026-09-16 September 16, 2026 01:01
@Hydralerne
Hydralerne merged commit 380d252 into oblien:feat/bugfix-batch-2026-09-16 Sep 16, 2026
@Farahat612
Farahat612 deleted the fix/426-terminal-session-leak branch October 23, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Terminal session counter not reset after browser disconnect — ghost sessions block new shells indefinitely

2 participants