Repository navigation
linux: treat ENOENT/EINVAL from pidfd_open as ESRCH - #2402
Merged
Merged
Conversation
pidfd_open(2) with flags=0 fails if the pid is not a thread-group leader. Older kernels report this as EINVAL (also used when the task is being reaped), while Linux >= 6.16 reports ESRCH for a reaped task and ENOENT for a pid which is not a thread-group leader (see kernel commits 8cf4b738f6d8 and 17f1b08acf50). The container init process is a thread-group leader, and it can't lose this status while alive, so both errors mean the process is gone and its pid number was either reused by a thread of another process, or is being released. Currently, EINVAL is handled by re-checking the pid validity, which is redundant, and ENOENT is not handled at all, resulting in an "open pidfd: No such file or directory" error on newer kernels. Map both EINVAL and ENOENT to ESRCH. Assisted-by: Claude Code (claude-opus-5-5) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Since the previous commit, libcrun_kill_linux maps EINVAL (and ENOENT) from pidfd_open to ESRCH, so there is no need to check for it here. Assisted-by: Claude Code (claude-opus-5-5) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin
enabled auto-merge
October 22, 2026 06:25
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.
pidfd_open(2)with flags=0 fails if the pid is not a thread-group leader.Older kernels report this as EINVAL (also used when the task is being
reaped), while Linux >= 6.16 reports ESRCH for a reaped task and ENOENT for
a pid which is not a thread-group leader (kernel commits 8cf4b738f6d8 and
17f1b08acf50).
The container init process is a thread-group leader and can't lose this
status while alive, so both errors mean the process is gone and its pid
number was either reused by a thread of another process, or is being
released.
Currently, EINVAL is handled by re-checking the pid validity, which is
redundant, and ENOENT is not handled at all, so on newer kernels
crun delete --forcefails with "open pidfd: No such file or directory".This maps both EINVAL and ENOENT to ESRCH in
libcrun_kill_linux, and dropsthe now-unneeded EINVAL check from
container_delete_internal.Closes: #2399