Skip to content

feat!: kill spawned commands when their namespace or patchbay ends - #101

Open
Frando wants to merge 2 commits into
mainfrom
feat/process-lifetime
Open

Frando wants to merge 2 commits into
mainfrom
feat/process-lifetime

Conversation

@Frando

@Frando Frando commented Nov 26, 2026

Copy link
Copy Markdown
Member

Summary

Commands from spawn_command and spawn_command_sync (on a device, a router, the IX, and as_root) outlived the patchbay process. After kill -9, they kept running, and also after a normal exit if their handles were dropped. They also outlived their lab, device, or router.

The kernel now sends such a process SIGKILL when the namespace worker thread that spawned it ends (PR_SET_PDEATHSIG). That thread ends with the patchbay process, with the lab, and when its device or router is removed.

Ctrl-C in a terminal already ended these commands, because they share the foreground process group. That still holds, and now also for a command that ignores SIGINT.

The first commit moves the spawn code, which Device, Router, Ix and AsRoot each repeated, into two NetnsManager methods. The second adds the signal there.

Breaking changes

  • A spawned process now gets SIGKILL when its lab drops or its device or router is removed. Code that keeps a Child after that sees it killed.

Limits

  • The signal does not reach processes that the command starts in turn, for example sh -c "server &".
  • The kernel clears it when the command is a setuid program or has file capabilities.

Tests

  • tests/process_lifetime.rs runs its own binary as a patchbay process that spawns three commands, one of them as root. The commands ignore SIGINT and SIGTERM. The tests then end that process with SIGKILL, with Ctrl-C (SIGINT to its process group), or with a normal exit. Without this change, the SIGKILL and Ctrl-C tests fail with "3 commands outlived their process".
  • spawned_command_ends_with_its_namespace checks a device removal and a lab drop.

#45 (containers) builds on this.

🤖 Generated with Claude Code

Frando and others added 2 commits November 26, 2026 15:01
Device, Router, Lab and AsRoot each repeated the code that spawns a
command on a namespace's sync worker. It now lives in two NetnsManager
methods.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A command from spawn_command or spawn_command_sync kept running after the
patchbay process died, for example on `kill -9`, and after its lab or
device was gone. The kernel now sends it SIGKILL when the spawning
namespace worker ends (PR_SET_PDEATHSIG). The worker ends with the
patchbay process, with the lab, and when its device or router is removed.

The signal does not reach processes that the command starts, nor a setuid
program or one with file capabilities.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant