The Docker docs run `magpie web --addr 0.0.0.0:3430 --no-open`, so in a
container without an init `magpie web` is PID 1 and adopts every orphan.
382c8c0bd made `serve` reap them (proc.KeepReaping) and left `web` out.
A plugin's backend whose host had ended (magpie-gemini-web's
aistudio2api) then stayed <defunct> under magpie for good, and the
plugin, asking kill(pid, 0), took it for still running and refused
every restart.
Run:
- TestLongRunningCommandsReap (internal/cli): serveCmd and webCmd each
call proc.KeepReaping. Red with origin/main's web_cli.go, green here.
- Real use on Linux (WSL2 Ubuntu 24.04, `unshare -Urpf --mount-proc`
so magpie is PID 1, sandbox HOME), an orphan left in the namespace
that exits after 1s: on origin/main `web` still had 1 zombie after
12s, `serve` 0; with this change both have 0.
- go test ./internal/cli -run TestLongRunningCommandsReap on mica.
- Full suite (-timeout 45m) and GOOS=linux/windows go vet on mica:
started at this tree before the push; result follows.
Not tried: the reporter's container itself. The plugin's own check is
fixed in BUKOWSKIREAL/magpie-gemini-web#59; the plugins repo's 18
siblings are magpie-community/plugins#1164.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"testing"
|
|
)
|
|
|
|
// TestLongRunningCommandsReap: `magpie serve` and `magpie web` are what a
|
|
// container runs as its PID 1 (the Dockerfile's CMD and the Docker docs'
|
|
// `web --addr 0.0.0.0:3430 --no-open`), and PID 1 is left every orphan to
|
|
// reap. `web` didn't call proc.KeepReaping, so an aistudio2api whose
|
|
// plugin host had ended stayed <defunct> under it, and the plugin waited
|
|
// on it for good (swang20201 on X).
|
|
func TestLongRunningCommandsReap(t *testing.T) {
|
|
f, err := parser.ParseFile(token.NewFileSet(), "web_cli.go", nil, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reaps := map[string]bool{}
|
|
for _, d := range f.Decls {
|
|
fn, ok := d.(*ast.FuncDecl)
|
|
if !ok || fn.Body == nil {
|
|
continue
|
|
}
|
|
ast.Inspect(fn.Body, func(n ast.Node) bool {
|
|
if c, ok := n.(*ast.CallExpr); ok {
|
|
if s, ok := c.Fun.(*ast.SelectorExpr); ok && s.Sel.Name == "KeepReaping" {
|
|
if x, ok := s.X.(*ast.Ident); ok && x.Name == "proc" {
|
|
reaps[fn.Name.Name] = true
|
|
}
|
|
}
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
for _, cmd := range []string{"serveCmd", "webCmd"} {
|
|
if !reaps[cmd] {
|
|
t.Errorf("%s doesn't call proc.KeepReaping: as a container's PID 1 it leaves its adopted orphans <defunct>", cmd)
|
|
}
|
|
}
|
|
}
|