Skip to content

Commit e9e99c0

Browse files
PR Batch Testerclaude
andcommitted
fix(ssh): stop this key's own stale server before taking over another key's
Matches the external-adoption branch, so a hung server this key still recorded is not orphaned. The test now starts from the external record earlier launchers left behind. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 1ea9e7e commit e9e99c0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,12 +458,15 @@ server.listen(Number(flag("--port")), "127.0.0.1", () => {
458458
assert.equal(launched.serverKind, "managed");
459459
const pid = yield* readManagedPid("old-alias");
460460

461+
// Earlier launchers recorded the renamed key as external.
462+
yield* fs.makeDirectory(stateDir("new-alias"), { recursive: true });
463+
yield* fs.writeFileString(`${stateDir("new-alias")}/managed`, "external\n");
461464
assert.deepEqual(yield* launch("new-alias"), launched);
462465
assert.equal(yield* readManagedPid("new-alias"), pid);
463466
assert.isFalse(yield* fs.exists(`${stateDir("old-alias")}/managed`));
464467
assert.isTrue(isAlive(pid));
465468

466-
// The server came from new-alias's runner, so a different runner under
469+
// new-alias now holds the server's runner, so a different runner under
467470
// the next key is an update and replaces it.
468471
yield* fs.writeFileString(`${stateDir("new-alias")}/run-t3.sh`, "# previous runner\n");
469472
assert.equal((yield* launch("newer-alias")).serverKind, "managed");

‎packages/ssh/src/tunnel.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ elif [ -n "$DEFAULT_REMOTE_PORT" ] && PREVIOUS_STATE_DIR="$(launcher_state_dir_f
669669
else
670670
RUNNER_CHANGED=1
671671
fi
672+
if [ "$REMOTE_MANAGED" = "managed" ] && [ -n "$REMOTE_PID" ] && kill -0 "$REMOTE_PID" 2>/dev/null; then
673+
kill "$REMOTE_PID" 2>/dev/null || true
674+
wait_for_pid_exit "$REMOTE_PID"
675+
fi
672676
REMOTE_PID="$DEFAULT_RUNTIME_PID"
673677
REMOTE_PORT="$DEFAULT_REMOTE_PORT"
674678
REMOTE_MANAGED="managed"

0 commit comments

Comments
 (0)