Skip to content

PERF: Remove child-exit polling from Landlock.capture - #4

Merged
tgxworld merged 6 commits into
mainfrom
tgxworld/fix-process-capture-polling
Aug 20, 2026
Merged

PERF: Remove child-exit polling from Landlock.capture#4
tgxworld merged 6 commits into
mainfrom
tgxworld/fix-process-capture-polling

Conversation

@tgxworld

@tgxworld tgxworld commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Previously, Landlock.capture polled 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.

@tgxworld
tgxworld force-pushed the tgxworld/fix-process-capture-polling branch from 164817e to 133082c Compare August 20, 2026 03:10
@tgxworld tgxworld changed the title FIX: avoid polling captured subprocesses FIX: Avoid 100 ms delay when captured processes exit Aug 20, 2026
@tgxworld
tgxworld force-pushed the tgxworld/fix-process-capture-polling branch from 4a2f520 to 133082c Compare August 20, 2026 04:08
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
SamSaffron marked this pull request as ready for review August 20, 2026 05:30
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.
@tgxworld tgxworld changed the title FIX: Avoid 100 ms delay when captured processes exit FIX: Avoid capture polling delays without weakening timeouts Aug 20, 2026
Keep the gem at version 0.4 and record the capture polling fix under the Unreleased changelog section until the next release is prepared.
@tgxworld tgxworld changed the title FIX: Avoid capture polling delays without weakening timeouts PERF: Remove child-exit polling from Landlock.capture Aug 20, 2026
@tgxworld
tgxworld merged commit f9beb8a into main Aug 20, 2026
6 checks passed
@tgxworld
tgxworld deleted the tgxworld/fix-process-capture-polling branch August 20, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants