The second way acezan's 57 <defunct> magpie-bun (v0.1.2819, a Linux
systemd service, 47 hours) pile up: magpie web's restart to update
(AutoRestart) runs the new version with syscall.Exec in the same pid.
The running plugin host was the old image's child, and the old image's
host.read held the only Wait for it. After the exec nothing waits for
it, so it ends on stdin EOF and stays <defunct> under that pid, one per
restart to update. skygunner reproduced it and AAEE86 counted 22 zombies
for 23 images under one pid (#3285). With about a hundred releases a
day, an AutoRestart service makes about one a hour, as acezan's did.
- plugin.EndHosts (host.go) stops every host started and not yet
reaped, including the retiring ones, waits until each one has been
waited for, and refuses to start another (errHostsEnded). startOn
starts the host and records it under one lock (live), so a host that
starts during EndHosts isn't missed.
- Web.Wait calls it right before update.Reexec.
Run at 72bc741ef (on origin/main 40a287b21, after the previous commit):
- mote (macOS): gofmt -l clean; go vet ./internal/gui ./internal/plugin,
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok.
go test -count=1 -timeout 45m ./internal/plugin: ok; -run Web
./internal/gui: ok.
- WSL magpie-desktop (Linux): ./internal/plugin ok, including
TestEndHostsLeavesNoChild and TestHostReapedWhileItsChildHoldsStdout
with a real Bun host; -race -count=3 of both: ok; go vet -tags nogui
and -run Web of ./internal/gui: ok.
Both commits were then rebased onto 0acba61a3, which changes only
app.js and plugin-checkin.test.cjs; no Go file these runs built moved,
and they were not run again there.
Broken by hand: EndHosts returning at once makes
TestEndHostsLeavesNoChild fail on Linux ("children left once EndHosts
returned: [16459 S bun]").
Not tried: a real magpie web restart to update (a downloaded update
exec'd in the same pid) on Linux. The test covers EndHosts, not the
exec. Not changed: anything else alive at the exec (pii's helper,
awake's caffeinate, #4188) still outlives it the same way.
Reported by acezan on Discord. Diagnosed in #3285 by skygunner and
AAEE86.