Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(cli): exit coder ssh --stdio when stdin closes before connection - #28597

Open
Tyagiquamar wants to merge 2 commits into
coder:mainfrom
Tyagiquamar:fix/ssh-stdio-stdin-eof
Open

fix(cli): exit coder ssh --stdio when stdin closes before connection#28597
Tyagiquamar wants to merge 2 commits into
coder:mainfrom
Tyagiquamar:fix/ssh-stdio-stdin-eof

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Fixes #27954

Problem

On Windows, coder ssh --stdio proxy 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 required taskkill /F to clear.

Root cause

In stdio mode nothing reads stdin before copier.copy starts. 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.Pipe starting 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:

$ go test ./cli/ -run 'TestSSHStdio_ExitWhenStdinClosedBeforeAgentConnects' -count=1

main (60b03138a):
    --- FAIL: TestSSHStdio_ExitWhenStdinClosedBeforeAgentConnects (17.09s)
        ssh_test.go:2498: coder ssh --stdio did not exit after stdin was closed

branch:
    --- PASS: TestSSHStdio_ExitWhenStdinClosedBeforeAgentConnects (2.57s)

Additional verification run locally on windows/amd64, Go 1.26.5:

$ go test ./cli/ -run 'TestSSH' -count=1 -timeout 2400s
ok      github.com/coder/coder/v2/cli   51.426s

$ gofmt -l cli/ssh.go cli/ssh_test.go        # no output
$ go vet ./cli/                              # exit 0

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.

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
Tyagiquamar marked this pull request as ready for review August 31, 2026 06:36
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Tyagiquamar

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@Tyagiquamar

Copy link
Copy Markdown
Author

recheck

2 similar comments
@Tyagiquamar

Copy link
Copy Markdown
Author

recheck

@Tyagiquamar

Copy link
Copy Markdown
Author

recheck

@Tyagiquamar

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@Tyagiquamar

Copy link
Copy Markdown
Author

recheck

@Tyagiquamar

Copy link
Copy Markdown
Author

Hi @DanielleMaywood, could you please review when you have a chance? Thanks!

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: Windows orphaned coder ssh --stdio processes after interrupted Codex connection retries

1 participant