Skip to content

Mark a VS Code pty-host child's terminals exited when its IPC channel closes before it exits - #1872

Open
dormouse-bot wants to merge 1 commit into
mainfrom
fix/pty-host-disconnect-before-exit
Open

dormouse-bot wants to merge 1 commit into
mainfrom
fix/pty-host-disconnect-before-exit

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

In the VS Code extension, a pty-host child that crashes can leave its terminals looking alive forever: no exit is reported, getPtyStatus says alive: true, and the panes never produce output again. This PR retires a child as soon as ensureChild sees its IPC channel closed, through the same code its exit handler runs, so every live PTY is marked exited and the webview hears onExit.

The race. Node emits disconnect separately from exit, and the pty-host shuts itself down on disconnect (pty-host.js). ensureChild treated any child with connected === false as replaceable and forked a new one. If a write, resize, getCwds, or another sendToChild call landed between the two events, child was reassigned, and the old child's exit handler then returned early on child !== launchedChild. That skipped the retirement docs/specs/vscode.md requires ("a pty-host child crash reports every live PTY exited and keeps its buffer").

The fix. The retirement block moves into retireChild, which the exit handler still calls and which now also runs in ensureChild before a fork when the current child is disconnected. Afterwards ensureChild checks again whether an onExit callback already forked the replacement (the existing "keeps a replacement spawned synchronously by an exit callback alive" case), so it never forks two. A late exit from the retired child is still ignored.

Verification. The new test in vscode-ext/test/pty-manager.test.ts drops the fake child's connected, writes, then emits exit. Before the fix it failed with alive still true; it passes now, along with the rest of that file. tsc is clean. Running vitest locally shows 90 failures in burrow, peer-link, peer-endpoint, and outbound. Unmodified main fails the same 90 tests in this sandbox, which can't open their sockets, so they're left to CI.

A send between the child's disconnect and its exit forked a replacement, so
the old child's exit handler returned early and its PTYs stayed alive with no
exit ever reported. ensureChild now retires a disconnected child before
forking, through the same path its exit takes.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4cd630b
Status: ✅  Deploy successful!
Preview URL: https://c96f13cc.mouseterm.pages.dev
Branch Preview URL: https://fix-pty-host-disconnect-befo.mouseterm.pages.dev

View logs

This branch has not been deployed

No deployments
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.

1 participant