Skip to content

test(sleeper_thread): raise the subprocess watchdog from 5s to 60s - #5518

Merged
Alexays merged 1 commit into
Alexays:masterfrom
guttermonk:fix/sleeper-thread-test-alarm-budget
Nov 21, 2026
Merged

Alexays merged 1 commit into
Alexays:masterfrom
guttermonk:fix/sleeper-thread-test-alarm-budget

Conversation

@guttermonk

Copy link
Copy Markdown
Contributor

run_in_subprocess() arms alarm(5) as a guard against a deadlocked child
hanging 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 stop runs
200 rounds of: a 2 ms 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 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)

condition result
idle (load 0.4) 0.44 s per run, 25/25 passed
all 16 cores busy over 5 s, 12/12 killed by the alarm
pinned to 4 cores, idle over 5 s, killed
pinned to 2 cores, idle over 5 s, killed

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

WIFEXITED is false for an alarmed child, so run_in_subprocess() returns its
-1 sentinel and the assertion reports:

../test/utils/sleeper_thread.cpp:166: FAILED:
  REQUIRE( run_in_subprocess(run_control_flag_stress) == 0 )
with expansion:
  -1 == 0

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 the
alarm fire, at the instant of death:

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

No thread is blocked on the SleeperThread mutex, none is in condvar wait, and
no 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 stays
meaningful — 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.

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.
@Alexays
Alexays merged commit b4f03e6 into Alexays:master Nov 21, 2026
12 checks passed
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.

2 participants