Skip to content

cmd/ate-env-guest: run under a minimal PID 1 init to reap orphaned children - #106

Open
Tomer Glottmann (tomergee) wants to merge 1 commit into
mainfrom
fix/guest-pid1-reaper-105
Open

Tomer Glottmann (tomergee) wants to merge 1 commit into
mainfrom
fix/guest-pid1-reaper-105

Conversation

@tomergee

Copy link
Copy Markdown
Collaborator

Fixes #105.

Problem

Inside an actor container or microVM, ate-env-guest starts as PID 1 (/proc/1/comm = ate-env-guest). PID 1 inherits every orphaned descendant whose parent exits first, and is the only process that can reap them. ate-env-guest waits on its own direct children (guest/process/tracker.go and cmd/ate-env-guest/sidecar.go), but had no orphan reaper, causing reparented grandchildren to accumulate as zombies (Z) for the lifetime of the guest.

Solution

  • Add runIfPID1() in cmd/ate-env-guest/init_linux.go (invoked at the start of main()), following the same minimal-init pattern as agent-substrate/substrate#2626.
  • When os.Getpid() == 1, PID 1 re-executes ate-env-guest as a supervised child process, forwards termination/user signals (SIGTERM, SIGINT, SIGHUP, SIGQUIT, SIGUSR1, SIGUSR2) to it, and loops syscall.Wait4(-1, &status, syscall.WNOHANG, nil) on SIGCHLD to reap all reparented orphans without racing os/exec's cmd.Wait() in the guest server.
  • Add unit tests (TestSuperviseReturnsExitCode, TestSuperviseReturnsSignalExitCode, TestSuperviseReapsOrphans, TestSuperviseForwardsSignals) using PR_SET_CHILD_SUBREAPER.

…ildren

When ate-env-guest starts as PID 1 inside an actor container or microVM, re-execute the guest server as a supervised child process and reap all reparented descendants in PID 1 via wait4(-1, WNOHANG) without racing os/exec's cmd.Wait() in ProcessService or sidecar supervisors.

Fixes #105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ate-env-guest runs as PID 1 inside an actor but never reaps orphaned children; zombies accumulate for the life of the guest (9,144 in 18.5 h)

1 participant