PERF: Remove child-exit polling from Landlock.capture - #4
Merged
Conversation
tgxworld
force-pushed
the
tgxworld/fix-process-capture-polling
branch
from
August 20, 2026 03:10
164817e to
133082c
Compare
tgxworld
force-pushed
the
tgxworld/fix-process-capture-polling
branch
from
August 20, 2026 04:08
4a2f520 to
133082c
Compare
Use pidfds to wait for captured children after their output streams close, avoiding timeout threads while preserving wall-clock deadline enforcement. Fall back to bounded polling when pidfds are unavailable, and ensure pidfd resources are closed on success and error paths.
SamSaffron
marked this pull request as ready for review
August 20, 2026 05:30
SamSaffron
approved these changes
Aug 20, 2026
A pidfd or polling wait could observe child completion after its wall-clock deadline and still report success when the parent resumed late. This commit rechecks the monotonic deadline before accepting either readiness path. Late completions remain timed out and trigger process-group cleanup, while on-time exits retain the direct wait behavior.
The polling fallback can cross its deadline while wait2 reaps the child. Signaling the process group afterward risks targeting an unrelated process if the PID has already been reused.\n\nKeep the late result marked as timed out, but do not terminate after reaping it. Exercise the exact deadline crossing through the public capture API and verify that no signal follows the reap.
A polling wait can reap the direct child after its deadline while same-group descendants remain alive. The existing generic termination path cannot be used safely because it may fall back to the now-recyclable positive PID. Send one immediate KILL only to the process group, retain the direct child status, and keep the result marked as timed out. Cover the race through the public capture API with a live descendant and reject positive-PID signals after reap.
Keep the gem at version 0.4 and record the capture polling fix under the Unreleased changelog section until the next release is prepared.
Landlock.capture
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.
Previously,
Landlock.capturepolled a child every 100 ms while reading its stdout and stderr. If both streams reached EOF just before the child became waitable, capture still slept for the polling interval, so some short commands took about 100 ms longer than the work itself.This commit separates output draining from child-exit waiting. After both streams close, captures without a timeout wait directly for the child. Captures with a wall-clock timeout monitor a Linux pidfd until either the child exits or the monotonic deadline expires, with bounded polling retained when pidfds are unavailable.