Skip to content

fix(exec): skip the 50 ms sweep retry when every new process was readable - #539

Open
cristianob wants to merge 1 commit into
herdrdev:masterfrom
cristianob:fix/exec-sweep-floor
Open

cristianob wants to merge 1 commit into
herdrdev:masterfrom
cristianob:fix/exec-sweep-floor

Conversation

@cristianob

Copy link
Copy Markdown

What happened

Even a command that exits immediately, such as hc exec /usr/bin/printf ready, takes longer than it needs to. The caller waits for cleanup before it gets the result.

Cause

When the first SIGHUP scan finds no scope members, sweep() always sleeps for 50 ms and scans again. A retry can catch a process whose environment was briefly unreadable during exec.

Fix

Keep the 50 ms retry when the first scan finds no scope members and encounters a process that started at or after the oldest token timestamp whose environment it cannot read. If that scan has no members and no unreadable candidates, return immediately.

A process of another user that started during the exec also counts as unreadable, so on a busy host some calls still take the retry. That is the previous behaviour, never less safe.

Test

  • sweep_waits_if_a_new_process_has_no_readable_environment starts a Linux process with an empty environment and checks that sweep() still waits at least 50 ms and leaves the process running.
  • In disposable Linux cores, hc exec /usr/bin/printf ready returned the expected output on every run. Across 30 calls per build after warm-up, the median went from 90.73 ms on master to 16.35 ms with the fix. The same check failed before the fix and passed after it with a 60 ms median threshold.
  • just check passed with the CI toolchain and test debug settings, using two test threads.

🤖 Generated with Claude Code

…able

sweep() slept 50 ms and scanned again whenever the first SIGHUP scan found
no scope members, which put a floor under every exec. Retry only when that
scan met a process newer than the token whose environment it could not
read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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