shell: clean up stale ssh.sock on --reconnect when the master is already dead#5165
Merged
AkihiroSuda merged 1 commit intoJul 2, 2026
Conversation
50f47cc to
4af98f1
Compare
AkihiroSuda
reviewed
Jun 29, 2026
AkihiroSuda
reviewed
Jun 29, 2026
…ady dead `limactl shell --reconnect` failed with `exit status 255` when the SSH ControlMaster socket existed but its master process had already exited (unclean hostagent shutdown: kill -9, OOM, host crash) -- the exact wedged state --reconnect is meant to recover from. Gate the control-socket cleanup on a liveness probe: only remove the socket when no master is listening on it, so a genuine `ssh -O exit` failure against a live master is still surfaced as an error. Add sshutil.IsControlMasterRunning and sshutil.RemoveStaleControlMaster with unit tests, and use the latter in the shell --reconnect path. Fixes lima-vm#4913 Signed-off-by: gaurav0107 <[email protected]>
4af98f1 to
7e8cdda
Compare
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.
Summary
limactl shell --reconnect <inst>is the documented escape hatch (added in #3125) for resetting a wedged SSH multiplexed session. Today it fails withexit status 255when the SSH ControlMaster socket file (<instDir>/ssh.sock) still exists but the master process is already dead — which is exactly the wedged state--reconnectis meant to recover from.sshutil.IsControlMasterExistingis a pureos.Stat; it does not verify the master is alive. After an unclean hostagent exit (kill -9, OOM, host crash, or the Cygwin/msys2 emulation file outliving its process) the socket survives.ssh -O exitthen fails and the error was returned directly, so--reconnectexited non-zero with no recovery.Changes
sshutil.IsControlMasterRunning(instDir)— dials the control socket to check whether a master is actually listening (a stale socket has no listener).sshutil.RemoveStaleControlMaster(instDir)— removes the control socket only when no master is listening; a live master's socket is never touched, and a missing socket is a no-op.cmd/limactl/shell.go, onssh.ExitMasterfailure during--reconnect, remove the socket only if it is confirmed stale; if a master is still alive the original error is still returned.This keeps the behavior unchanged for a live master (a genuine
ssh -O exitfailure is still surfaced) and recovers automatically when the master is already dead.Test plan
pkg/sshutil/sshutil_test.go(TestControlMasterStale):go test ./pkg/sshutil/...go vet ./...gofmt -l(clean)go build ./...Fixes #4913