Repository navigation
Stop clickhouse_fuzzer from self-inflicting timeouts via SIGALRM signals - #105176
Conversation
libfuzzer arms `setitimer(ITIMER_REAL)` with an interval of `UnitTimeoutSec / 2 + 1` seconds (11 s for our 20 s timeout), so SIGALRM fires periodically — not only at the actual timeout. The wrapper handler in `clickhouse_fuzzer.cpp` had three issues that together produced spurious "timeout after 21 seconds" failures (seen on PRs #99740 and #104869): 1. SIGALRM has no per-thread routing. The handler is installed process-wide via `sigaction`, so the kernel can deliver it to either the libfuzzer main thread or the runner thread. When it landed on the runner, `fuzzerSigalrmHandler` `pthread_kill`'d SIGUSR1 to itself and raced with a concurrent invocation on the main thread, with two competing `sigaction` restores corrupting handler state. 2. The slow runner-stack dump (shells out to llvm-symbolizer) ran on every periodic SIGALRM, even when the iteration was nowhere near its timeout. The dump alone takes many seconds; combined with the 3-second wait-for-stack window it could push an otherwise-fast iteration past the 20 s limit and trigger a real timeout. 3. The wrapper permanently restored libfuzzer's original handler before `raise(SIGALRM)`, making itself one-shot. A periodic SIGALRM at second ~11 consumed the wrapper, so when the genuine timeout fired at second 20 there was no longer any wrapper to dump the runner stack. Fix all three: - Block SIGALRM on the runner thread at the top of `runLibFuzzer` so the wrapper only ever runs on the libfuzzer main thread. - Track per-iteration start time via `clock_gettime(CLOCK_MONOTONIC)` and skip the SIGUSR1 stack-dump unless elapsed ≥ 15 s, so the 11 s periodic alarms pass through without disturbing the runner. Guard with an atomic to keep the dump single-shot per process. - Call libfuzzer's original handler directly (via the saved `sigaction.sa_sigaction` / `sa_handler`) instead of permanently restoring it. The wrapper stays installed and keeps intercepting later alarms. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104869&sha=4bb6825eb6220feaca31f3d2608dae09d5de7927&name_0=PR&name_1=libFuzzer%20tests #104869 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Workflow [PR], commit [3d82b2e] Summary: ✅ AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
…out=N` The wrapper's previous hardcoded `timeout_imminent_sec = 15` was wrong for any `-timeout` other than the 20 s default: - With `-timeout=30`, libfuzzer fires SIGALRM at ~16 s and ~32 s. The first alarm already satisfies `elapsed >= 15`, so `dump_started` is consumed before any real timeout; the second alarm at 32 s (the actual timeout) then skips the runner-stack dump. - For `-timeout < 15`, the dump is never attempted. Match libfuzzer's own condition instead: - Parse `-timeout=N` from argv in `LLVMFuzzerInitialize` into a file-scope `unit_timeout_sec` atomic (default 1200, libfuzzer's default). - Trigger the dump when `elapsed_sec >= unit_timeout_sec`, which is exactly when libfuzzer's `AlarmCallback` declares a timeout, so the periodic `UnitTimeoutSec / 2 + 1` second ticks pass through untouched at every `-timeout=N` value. - Move `dump_started` from a function-scope `static` to file scope and reset it at the top of each `LLVMFuzzerTestOneInput` call, so a stray late SIGALRM in one iteration cannot suppress the dump on a real timeout in a later iteration.
|
@groeneai, the only test-job failure on this PR is
This is unrelated to the change in this PR (which only touches CIDB shows this test failing with the same |
|
@alexey-milovidov — already fixed and merged this morning, but this PR (#105176) predates the merge so it doesn't yet carry the fix. Timeline:
Master HEAD has CIDB confirms master is fully stable post-merge — every failure since 08:08:57 UTC is on an unrebased PR:
(9+ hours, 0 master failures.) The 6 PRs that hit the failure post-merge — #101354, #101039, #100377, #99774, #104513, #104606, and this PR — are all branched off pre-#105194 master. Recommended action: merge (Cron session: |
Two comment corrections: 1. The `dump_started` comment said "concurrent SIGALRM deliveries can't run the dump in parallel" — but since SA_NODEFER is not set, the kernel blocks SIGALRM while the handler executes, so there is no true concurrency. The guard actually prevents multiple *sequential* re-invocations (from pending signals delivered after the handler returns) from repeating the dump within one iteration. 2. The comment describing libfuzzer's timeout condition said `elapsed > UnitTimeoutSec` but the actual code in FuzzerLoop.cpp uses `Seconds >= (size_t)Options.UnitTimeoutSec`. The wrapper's code already correctly uses `>=`; only the comment was wrong. Co-authored-by: Yakov Olkhovskiy <[email protected]>
|
|
…uzzer-signal-races Stop clickhouse_fuzzer from self-inflicting timeouts via SIGALRM signals
Two comment corrections: 1. The `dump_started` comment said "concurrent SIGALRM deliveries can't run the dump in parallel" — but since SA_NODEFER is not set, the kernel blocks SIGALRM while the handler executes, so there is no true concurrency. The guard actually prevents multiple *sequential* re-invocations (from pending signals delivered after the handler returns) from repeating the dump within one iteration. 2. The comment describing libfuzzer's timeout condition said `elapsed > UnitTimeoutSec` but the actual code in FuzzerLoop.cpp uses `Seconds >= (size_t)Options.UnitTimeoutSec`. The wrapper's code already correctly uses `>=`; only the comment was wrong. Reference: ClickHouse#105176 Co-authored-by: Yakov Olkhovskiy <[email protected]>
…a timeout The nightly `clickhouse_fuzzer` run on master reported `libFuzzer: timeout after 28 seconds` on a 228-byte input that runs in milliseconds: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=9f79cc172306dbf177534ef194cafc034a598a33&name_0=NightlyFuzzers&name_1=libFuzzer%20tests `fuzzerSigalrmHandler` decided that an alarm was the timeout with its own check: whole seconds since the start of the last `LLVMFuzzerTestOneInput`, a start that was never cleared when the callback returned. libFuzzer's `AlarmCallback` ignores an alarm that lands on another thread (every ClickHouse thread except the runner has SIGALRM unblocked) or arrives while no callback is running (for example the leak check after a seed). In such an alarm the wrapper sent SIGUSR1 to the idle runner, which then spent tens of seconds symbolizing its stack while libFuzzer carried on, and the next callback waited for it until libFuzzer timed that one out. Whole-second rounding could also trigger the dump up to a second early. Dump only on libFuzzer's own fatal condition: on the fuzzing thread, inside `LLVMFuzzerTestOneInput` (the start is now cleared on return), and with `-timeout` elapsed by `CLOCK_REALTIME` in nanoseconds, the clock libFuzzer uses. The wrapper's start is taken after libFuzzer's `UnitStartTime`, so a dump implies that libFuzzer exits at the same alarm. Validated with an x86 ASan libFuzzer build with the CI flags, `-timeout=2`, seeds that grow a `Memory` table (long leak checks) alternating with the CI input: the base binary reported a false timeout in 3 of 3 runs, the fix ran all 40 seeds in 8 of 8. A genuine timeout still exits with code 70, and a process-directed SIGUSR1 still stops fuzzing gracefully. Related: ClickHouse#105176 Co-Authored-By: Claude Opus 5.5 <[email protected]>
On the libFuzzer CI job,
clickhouse_fuzzerhas been failing intermittently withtimeout after 21 secondson trivial inputs (e.g.\"7\\0\\0\") where the runner-thread stack snapshot shows it idle atcv.wait, not running a query. CIDB shows 19 such hits on PR #99740 in April plus this fresh one on PR #104869.The wrapper in
programs/local/fuzzers/clickhouse_fuzzer.cppis fighting libFuzzer's own SIGALRM machinery.libFuzzerarmssetitimer(ITIMER_REAL)with an interval ofUnitTimeoutSec / 2 + 1seconds (11 s for our 20 s timeout), soSIGALRMfires periodically — not only at the actual timeout. The wrapper had three bugs that compounded into spurious timeouts:sigaction, the kernel could deliver it to either the libFuzzer main thread or the clickhouse-local runner thread. When it landed on the runner,fuzzerSigalrmHandlerpthread_kill'dSIGUSR1to itself and raced with a concurrent invocation on the main thread; two competingsigactionrestores then corrupted the handler state. The failing CI trace shows exactly that interleaving (#4 fuzzerSigalrmHandlerinside the runner's stack atclickhouse_fuzzer.cpp:212— thepthread_killline).__sanitizer_print_stack_traceshells out tollvm-symbolizer(fork+exec, not async-signal-safe) and can take many seconds. Combined with the 3-second wait-for-stack window, it could push an otherwise-fast iteration past the 20 s limit and trigger a real timeout — a self-fulfilling failure.raise(SIGALRM), making itself one-shot. A periodic alarm at second ~11 consumed the wrapper, so when the genuine timeout fired at second 20 there was no longer any wrapper to dump the runner stack.Fix all three:
SIGALRMon the runner thread at the top ofrunLibFuzzer(pthread_sigmask(SIG_BLOCK, …)) so the wrapper only runs on the libFuzzer main thread.clock_gettime(CLOCK_MONOTONIC)and skip theSIGUSR1stack-dump unless elapsed ≥ 15 s, so the periodic 11 s alarms pass through without disturbing the runner. Guard with an atomic to keep the dump single-shot per process.sigaction.sa_sigaction/sa_handlerinstead of permanently restoring it. The wrapper stays installed and keeps intercepting later alarms.CI report that surfaced this: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104869&sha=4bb6825eb6220feaca31f3d2608dae09d5de7927&name_0=PR&name_1=libFuzzer%20tests (PR #104869)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
🤖 Generated with Claude Code
Version info
26.5.1.913