Repository navigation
Conversation
…ombies under the process daemon User decisions: - Fix the zombie processes reported on 2.3.0
There was a problem hiding this comment.
Verified on Linux 7.3: the new finished_records_do_not_keep_unreaped_children test fails on dev and passes here, and the pipe suite passes on both (run under a subreaper; four orphan-dependent tests fail the same way on both without one, because this sandbox's PID 1 doesn't reap). The macOS path isn't run, but reading XNU/libproc, proc_listpgrppids does list zombies and returns a pid count, so the lone-zombie check should match as intended.
Public API unchanged: no wire protocol, CLI, config or SDK changes.
One gap worth deciding on (inline): Linux before 6.9 still keeps up to 25 zombies per Location. That covers Ubuntu 24.04 LTS (6.8), Debian 12 and RHEL 9, and one commenter on #63817 is on 6.8.
| // has been reaped and the numeric PID reused. Probe before reaping. | ||
| // SAFETY: pidfd_open returns a new owned descriptor on success. | ||
| let fd = unsafe { libc::syscall(libc::SYS_pidfd_open, self.pid, 0) }; | ||
| if fd < 0 { |
There was a problem hiding this comment.
On kernels without PIDFD_SIGNAL_PROCESS_GROUP (before 6.9) both early returns keep the child as a zombie, so the per-Location pile-up stays there. That covers Ubuntu 24.04 LTS (6.8), Debian 12 (6.1) and RHEL 9 (5.14), and a commenter on #63817 hits it on 6.8. Could Linux fall back to the macOS approach when the pidfd path isn't available? That would mean reaping if no other process in /proc has this pgrp, and otherwise rechecking on get/list. It has the same window as proc_listpgrppids, and would leave only the cmd & case reserved on old kernels.
|
Superseded by #64251, which restores the pre-2.3.0 behavior instead (reap at exit, leave a successful command's background processes alone, kill a failed command's group at exit) and retires old daemons on upgrade. |
Finished shell commands no longer pile up as zombie processes under the
opencode-ptydaemon. Reported on 2.3.0 (macOS, daemon 0.5.2): ~3–15<defunct>children of the daemon per hour on an always-on server, 0 on 2.2.5.❌ Before
waitid(WNOWAIT)and keeps it as a zombie until the record is forgotten, so its PID and process-group ID stay reserved for a laterkillpg(service/pipe/unix.rs).EXITED_LIMIT), and its hourly sweep only forgets records whose output file is gone or that are older than 7 days. With a few Locations that is dozens of zombies at any time.✅ After (daemon only; core unchanged)
The daemon separates the exit record from the authority to signal the group:
proc_listpgrppids), it is reaped at once and numeric signals are retired. If descendants survive (cmd &), the reservation stays andget/listre-check and release it once the group is empty.waitresults are kept, so restart recovery andShellTool.reattachstill report a command that finished during a handoff. The wire protocol is unchanged.🚩 Flag: none (fix).
📊 Proof
exit 0commands per scenario, countingZchildren of the daemon:finished_records_do_not_keep_unreaped_childrentest fails ondevand passes here.cargo test --locked: 147 passed, 1 ignored.cargo fmt --checkand Clippy (-D warnings, all targets) pass;cargo check --testsand Clippy pass foraarch64-apple-darwin.🚀 Release: needs an
opencode-ptyrelease, then an OpenCode release that pins it.Added by the opencode bot (AI-generated).
Fixes #63817
Fixes #63976
Related: #64177