🔧 fix: reap the vmhost child so mb down is fast#56
Open
yeazelm wants to merge 1 commit into
Open
Conversation
The daemon spawned each vmhost with Setsid and then `cmd.Process.Release()`, never wait()ing on it. When vmhost exits, it becomes a zombie of the daemon, and the `mb down` wait loop checks liveness with `processAlive` (kill -0) — which reports a zombie as alive. So `mb down` blocked for its full 45s ceiling even though the guest had powered off and vmhost exited within ~1s. Reap the child with `go cmd.Wait()` instead of releasing it. vmhost still runs in its own session, so it survives daemon exit and a daemon restart inherits it via init; while this daemon is alive it is the OS parent and must wait() on the child to avoid the zombie. With the PID reaped promptly, `mb down` returns in ~1s. Part of PCC-777.
| // (kill -0) still reports it as running, so `mb down` blocks for its full | ||
| // 45s timeout even though the VM stopped in ~1s. If the daemon exits first, | ||
| // init inherits and reaps vmhost instead. | ||
| go func() { _ = cmd.Wait() }() |
There was a problem hiding this comment.
The exit status from
cmd.Wait() is silently discarded. When vmhost crashes or exits non-zero, the daemon has no record of it — the only signal is the socket going dark. Logging the error here would make crash investigations easier without changing any behavior.
Suggested change
| go func() { _ = cmd.Wait() }() | |
| go func() { | |
| if err := cmd.Wait(); err != nil { | |
| d.logger.Printf("vmhost for %q exited: %v", inst.Name, err) | |
| } | |
| }() |
Prompt To Fix With AI
This is a comment left during a code review.
Path: pkg/daemon/daemon.go
Line: 414
Comment:
The exit status from `cmd.Wait()` is silently discarded. When `vmhost` crashes or exits non-zero, the daemon has no record of it — the only signal is the socket going dark. Logging the error here would make crash investigations easier without changing any behavior.
```suggestion
go func() {
if err := cmd.Wait(); err != nil {
d.logger.Printf("vmhost for %q exited: %v", inst.Name, err)
}
}()
```
How can I resolve this? If you propose a fix, please make it concise.
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
mb downtook ~45s even though the guest powered off in ~1s. The daemon spawnseach
vmhostwithSetsidand thencmd.Process.Release(), neverwait()ingon it — so when
vmhostexits it becomes a zombie of the daemon, and themb downwait loop checks liveness withprocessAlive(kill -0), which reportsa zombie as alive. The loop then blocked for its full 45s ceiling.
Fix: reap the child with
go cmd.Wait()instead of releasing it.vmhoststillruns in its own session, so it survives daemon exit and a restart inherits it via
init; while this daemon is alive it is the OS parent and must
wait()to avoidthe zombie. With the PID reaped promptly,
mb downreturns in ~1s.Test plan
gofmt/go vet/golangci-lintclean (0 issues)applevirtbackend:mb upthenmb downdrops from ~45s to ~1s; confirmed no lingering
<defunct>vmhostvmhoststill survives a daemon restart (Setsid; reattached on restart)Part of PCC-777.