Repository navigation
test(sleeper_thread): raise the subprocess watchdog from 5s to 60s - #5518
Merged
Alexays merged 1 commit intoNov 21, 2026
Merged
Conversation
run_in_subprocess() arms alarm(5) to stop a deadlocked child hanging the
suite. "SleeperThread control flags are stable under concurrent wake and
stop" does 200 rounds of: a 2ms sleep, a SleeperThread created/stopped/
joined, a waker thread created/joined, and 100 wake_up() calls each
followed by yield(). That is 400 thread create/join pairs and 20,000
sched_yield() calls.
Both are cheap with free cores and ruinous without: an oversubscribed
yield costs a scheduling quantum instead of nanoseconds. Measured on a
16-thread machine:
idle (load 0.4) 0.44s per run, 25/25 passed
all 16 cores busy over 5s, 12/12 killed by the alarm
pinned to 4 cores, idle over 5s, killed
pinned to 2 cores, idle over 5s, killed
So an 11x idle margin is not enough, and the failure mode is ugly:
WIFEXITED is false for an alarmed child, run_in_subprocess returns its
-1 sentinel, and the assertion reports "-1 == 0" with no hint that a
timeout was involved. It reads exactly like a deadlock.
It is not one. Under gdb, at the instant the alarm fires:
main thread std::thread::join() -> __pthread_clockjoin_ex
(the waker.join() at the end of a round)
waker thread sched_yield(), inside its own loop
Nothing is blocked on the SleeperThread mutex, nothing is in condvar
wait, and no thread holds a lock another wants. The waker is simply
still working when the clock runs out.
60s keeps the guard meaningful -- a real deadlock still fails in bounded
time rather than hanging CI -- while leaving roughly 140x headroom idle.
No test logic changes.
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.
run_in_subprocess()armsalarm(5)as a guard against a deadlocked childhanging the suite. One of the bodies it guards cannot reliably finish in that
budget on a busy machine, so a healthy run gets SIGALRM'd and reported as a
failure.
What the test does per run
SleeperThread control flags are stable under concurrent wake and stopruns200 rounds of: a 2 ms sleep, a
SleeperThreadcreated / stopped / joined, awaker thread created / joined, and 100
wake_up()calls each followed byyield().That is 400 thread create/join pairs and 20,000
sched_yield()calls. Bothare cheap when cores are free and ruinous when they are not — an oversubscribed
yield costs a scheduling quantum instead of a few hundred nanoseconds.
Measurements (16-thread machine)
An 11× idle margin sounds comfortable and isn't: the same work blows through
the budget under ordinary CI contention, or simply on fewer cores.
Why the failure is misleading
WIFEXITEDis false for an alarmed child, sorun_in_subprocess()returns its-1sentinel and the assertion reports:Nothing says a timeout was involved, so it reads as a deadlock in
SleeperThread. It isn't one. Under gdb, following the fork and letting thealarm fire, at the instant of death:
No thread is blocked on the
SleeperThreadmutex, none is in condvar wait, andno thread holds a lock another wants. The waker is still working when the clock
runs out.
The change
alarm(5)→alarm(60). One constant, no test logic touched. The guard staysmeaningful — a genuine deadlock still fails in bounded time rather than hanging
CI — while leaving roughly 140× headroom when idle. The alarm is shared by all
five cases in the file; the other four finish in milliseconds, so the larger
budget costs them nothing.