Skip to content

fix(ssh): disconnect no longer waits on a stopped server left as a zombie - #46053

Open
iamshadmantaqi wants to merge 3 commits into
pingdotgg:mainfrom
iamshadmantaqi:fix/ssh-stop-zombie
Open

iamshadmantaqi wants to merge 3 commits into
pingdotgg:mainfrom
iamshadmantaqi:fix/ssh-stop-zombie

Conversation

@iamshadmantaqi

Copy link
Copy Markdown
Contributor

Problem

Disconnecting an SSH environment on a host whose PID 1 never reaps exited processes fails with a stop error and a 2 second wait, even though the server did stop.

Steps (Linux, no sign-in):

  1. Start a container whose PID 1 does not reap: docker run -d -p 2222:22 <debian image with openssh-server and a key for user dev> sh -c '/usr/sbin/sshd && exec sleep infinity'.
  2. In T3 Code desktop on Linux, add an SSH environment for dev@localhost port 2222 and let it connect (the remote server starts).
  3. Remove the environment (or turn it off).
  4. Expected: the removal finishes at once. Actual: it waits about 2 extra seconds, then the desktop log has "Could not disconnect the managed SSH environment." with "Remote T3 server with PID N did not stop within 2 seconds. Its ownership files were kept." In the container, ps -o pid,stat,args -p N shows a Z <defunct> entry and ~/.t3/ssh-launch/<key>/pid still names it: the server exited, but nothing reaped it.

Cause

REMOTE_STOP_SCRIPT in packages/ssh/src/tunnel.ts:1097 stops the managed server, then waits for the exit with a bare kill -0 "$REMOTE_PID" (tunnel.ts:1115) and fails if kill -0 still passes after 2 seconds (tunnel.ts:1119). kill -0 accepts a zombie's PID, so on a host whose PID 1 never reaps orphans the loop always runs out and the script exits 1. The sibling REMOTE_MANAGED_SERVER_RUNNING_SCRIPT (tunnel.ts:598) already documents this in its comment at tunnel.ts:595, "kill -0 also passes for a zombie", and its managed_server_running helper checks the ps args so a zombie does not count. The stop script interpolates that helper and runs it before the kill (tunnel.ts:1112), but not after; the launch script's shutdown branches re-check with managed_server_running, not kill -0 (#19432, #26963).

Change

The stop script's wait loop and final check now use managed_server_running, the same rule the script already applies before the kill. Without ps it still falls back to kill -0, as before. Three lines change and one comment line is added, in one file.

Scope

Small fix of an obvious bug, steps reproduce it, so it needs no issue.

Verification

New case in packages/ssh/src/tunnel.test.ts, remote stop script > disconnecting stops a managed server whose exit is never reaped (skipped on Windows): a shell starts a node process with serve-like arguments in the background and then exec sleep 30, so nobody reaps it; the test records it as the managed server, runs the real stop script through disconnectEnvironment with sh -s under a temp HOME, and expects success and the pid file gone.

Test commit alone, fails on main faad516 (macOS /bin/sh):

FAIL  src/tunnel.test.ts > remote stop script > disconnecting stops a managed server whose exit is never reaped
SshCommandError: Remote T3 server with PID 55849 did not stop within 2 seconds. Its ownership files were kept.
Tests  1 failed | 60 skipped (61)

Again with sh pointing at /bin/dash on the PATH: 1 failed | 60 skipped (61), the same error.

With the fix, 1 passed | 60 skipped (61) under both shells. Whole file with the fix: 3 failed | 51 passed | 7 skipped (61); the three failures ("names missing gzip after verifying with sha256sum", "names missing gzip after verifying with shasum", "concurrent launches on one remote home record the server that owns it") fail identically on pristine main on this Mac, 3 failed | 50 passed | 7 skipped (60): the gzip pair because macOS tar unpacks gzip by itself, the third a timing flake. They are unrelated to this change.

vp run check:changed: format, lint, knip 1/2 and 2/2, and typecheck (5 packages) pass; the test step (2 files) fails only on the two gzip host failures, stable across a re-run.

Not verified: I did not start a real Docker container with sshd && exec sleep infinity, connect T3 Code to it over OpenSSH and remove the environment; the test reproduces the unreaped exit locally by spawning the server under a sleep parent and running the real stop script through disconnectEnvironment.

Model: Claude Opus 5.5. Harness: Claude Code in T3 Code.

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 30, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 277f78a

Macroscope's review found this PR approvable — SSH disconnect now recognizes an exited managed server instead of waiting on its zombie process. Existing server-ownership checks and shutdown safeguards remain unchanged.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 277f78a and a173e92.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The stop script now uses managed_server_running to check shutdown progress and determine whether to report a timeout. A POSIX-only test checks that disconnect removes the recorded PID file when the server’s exit is not reaped.

Changes: Managed server shutdown

Layer / File(s) Summary
Shutdown detection and regression test
packages/ssh/src/tunnel.ts, packages/ssh/src/tunnel.test.ts
The stop script uses managed_server_running during its shutdown wait and timeout check. The test checks PID-record removal after disconnect when the server’s exit is not reaped.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge, stienswout

Merge Risk: Minimal · previous review 277f7

This fixes SSH environment disconnect hanging or timing out when a stopped remote server stays a zombie. The change is small and localized, and a regression test covers it. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the actual change: disconnect no longer waits on a stopped server left as a zombie. It matches the stop script change that uses managed_server_running instead of kill -0, and the regre…
Description check Passed The description follows the template well. It has Problem, Change, Scope, and Verification sections. The Problem section gives reproduction steps and expected versus actual behavior. The Change sectio…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the actual change: disconnect no longer waits on a stopped server left as a zombie. It matches the stop script change that uses managed_server_running instead of kill -0, and the regression test. It uses the conventional commit format and is specific. The title is 73 characters, within normal length.

Full details: Description check

Explanation

The description follows the template well. It has Problem, Change, Scope, and Verification sections. The Problem section gives reproduction steps and expected versus actual behavior. The Change section explains the fix and why it is limited to one file. The Scope section explains why no issue is linked. The Verification section gives focused test commands, observed results under two shells, the unrelated pre-existing failures, and what was not verified. It also names the model and harness, as the template requests. The author did not link an issue but gave a reason for omitting it, which the template allows for small obvious bug fixes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between faad516 and 277f78a.

Files selected for processing: 2

  • packages/ssh/src/tunnel.test.ts
  • packages/ssh/src/tunnel.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

size:XS 0-9 changed lines (additions + deletions). takeover:in-progress A takeover lead is working on this PR vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants