fix(cli): exit coder ssh --stdio when stdin closes before connection - #28597
Open
Tyagiquamar wants to merge 2 commits into
Open
fix(cli): exit coder ssh --stdio when stdin closes before connection#28597Tyagiquamar wants to merge 2 commits into
Tyagiquamar wants to merge 2 commits into
Conversation
ProxyCommand clients close stdin when they abandon a connection attempt. Nothing read stdin before the SSH session was established, so on Windows (no parent-death signal) abandoned processes leaked while waiting for the agent or dialing. Relay stdin through a pipe and cancel the command when it terminates pre-connection; existing copy logic still owns stdin termination once connected. Closes coder#27954 Signed-off-by: Tyagiquamar <[email protected]>
Tyagiquamar
marked this pull request as ready for review
August 31, 2026 06:36
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
2 similar comments
Author
|
recheck |
Author
|
recheck |
Author
|
I have read the CLA Document and I hereby sign the CLA |
Author
|
recheck |
Author
|
Hi @DanielleMaywood, could you please review when you have a chance? Thanks! |
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.
Fixes #27954
Problem
On Windows,
coder ssh --stdioproxy processes leak when the ProxyCommand client (e.g. Codex Desktop) abandons or retries a connection attempt. The CLI does not observe stdin closing until the SSH session is established, so abandoned processes keep waiting for the agent or sit in dial retries. One reporter accumulated 283 orphaned processes (~7 GB working set) that requiredtaskkill /Fto clear.Root cause
In stdio mode nothing reads stdin before
copier.copystarts. Every pre-connection stage (workspace resolution, agent wait, dial retries, the Coder Connect probe) ignores stdin, so a pipe closed by a dead or giving-up parent is never noticed. Unlike Linux, Windows has no SIGHUP-style parent-death signal to fall back on, which is why the accumulation shows up there.Fix
Relay stdin through an
io.Pipestarting at command setup. If the relay observes EOF or a read error before the SSH session begins consuming stdin, the command cancels itself and exits. After connection, the existing copy logic keeps owning stdin termination exactly as before; an atomic flag set in both connection paths gates the cancel so established-session semantics do not change.Testing
New regression test fails on current main and passes with the fix:
Additional verification run locally on windows/amd64, Go 1.26.5:
Broader cli-package failures seen on this machine (TestRoot, TestGitSSH, TestDERPHeaders, TestCommandHelp, TestServer, TestWorkspaceAgent) were confirmed to reproduce identically on pristine main; for example TestRoot shells out to
cmd.exe /c printf, which does not exist on Windows. They are unrelated to this change.AI involvement: developed with AI assistance under human direction; the commands and results above were produced by running them locally, per the AI contribution guidelines.