Repository navigation
fix: remove the session pid file on exit - #53
Merged
Merged
Conversation
The parent exits with std::process::exit(), which skips destructors: the pid file was never removed, and every session left one behind. The next session removes pid files of dead processes, but when the PID has been reused, it enters the mount namespace of an unrelated process, where the overlay is not mounted, and the container gets an empty /nix. Drop the shared mount, and with it the pid file, before exiting. Check in the CI smoke test that no pid file is left after the sessions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Every session leaves its pid file in
<state>/rootful/pids(orrootless/pids): the parent dive process exits withstd::process::exit(), which skips destructors, soPidFile::dropnever runs.The next session removes pid files of dead processes, so they don't pile up, but if the PID has been reused,
enter_shared_mount_namespaceenters the mount namespace of that unrelated process — as root — where the overlay is not mounted: the container gets an empty/nix.Fix
shared_mount(and with it the pid file) in the parent beforeexit().exit(), or it would remove the parent's pid file.Testing
Real rootful sessions against an
alpine:3.22container, scratch state directory, withsudo:Not addressed
A pid file can still be left when dive is killed (SIGKILL, OOM), so the PID reuse issue remains possible after a crash. Checking that the process behind a pid file is dive before entering its namespace would cover it; the clean-up PR (#52) has a similar check (
/proc/<pid>/commstarts withdive) that could be shared.