Skip to content

Do not fuzz the stateful fixture load in the flaky check - #117997

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:do-not-fuzz-the-stateful-fixture-load
Sep 13, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:do-not-fuzz-the-stateful-fixture-load

Conversation

@groeneai

@groeneai groeneai commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #110321 (comment)

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The stateful fixture preparation in the flaky check no longer runs with ThreadFuzzer armed.

Description

@ alexey-milovidov asked me to investigate a Stateless tests (amd_tsan, flaky check) setup failure on #110321 and fix it separately (report): prepare_stateful_data was terminated at its bound on INSERT INTO test.hits_s3 SELECT * FROM test.hits, so the job produced no signal. It recurred on #117831 (report); 8 in 90 days, all in that lane.

Of the lanes that run functional_tests.py, only the flaky check arms ThreadFuzzer, and for the server's whole lifetime: the config is appended during INSTALL, so THREAD_FUZZER_CPU_TIME_PERIOD_US=1000 is set before the server starts, the constructor self-arms a process-wide setitimer(ITIMER_PROF), and nothing in this lane stops it. So the fixture load is fuzzed although nothing asserts on its interleaving, and pays 7.8x to 33x where it finishes (below). Under TSan there is no ceiling: each delivery takes one of 255 thread slots before dispatch, and one sleeping in the handler re-attaches one. In a wedged job's dump 576 of 684 threads sit in SlotLock, none in ClickHouse code; unfuzzed, the same TSan build runs it in 217 s.

This stops the fuzzer across prepare_stateful_data and starts it after, in the flaky check only, as tests/docker_scripts/stress_runner.sh already does before loading that table.

Validation: with the flag off the rendered script's argv log is byte-identical to master's; a mutant arm proves that check is not blind; the re-arm measures 3.00x, control 1.05x.

Not shown: the wedge did not reproduce locally (3 arms, 732-878 threads, fuzzer active, all completed), so the lane comparison is the attribution evidence; I do not claim the wedge fixed. This PR touches no test file, so the flaky lanes skip and its own CI never runs the new statements. SYSTEM STOP THREAD FUZZER leaves the SIGPROF timer armed; the stress lane runs that state and loads the same table in 91-155 s, so I left it.

Measurements

Cost of INSERT INTO test.hits_s3 SELECT * FROM test.hits, from the job logs of one commit (PR 117831, 24803f871cdf465dac768070f6e1326256647773):

build fuzzer off (lane) fuzzer on (flaky check) tax
debug 7 s (amd_debug, parallel) 229 s 33x
binary 10 s (amd_binary_excluded_from_llvm) 229 s 23x
asan_ubsan 98 s (amd_asan_ubsan, distributed plan, parallel, selected tests) 762 s 7.8x
msan - 296 s -
tsan 217 s (amd_tsan, parallel, selected tests), 291 s (sequential, selected tests) never completes >=14.5x

The controlled pair is the 217 s lane against the flaky check: both are m7i.8xlarge, both report test.hits = 8,873,898 rows, and the statement and max_insert_threads=4 are identical. The 291 s lane ran on an m7i.2xlarge, and the debug and binary rows compare different instance types, so read those as the size of the tax rather than as controls.

Occurrences: CIDB, 90 days, job-level rows of the flaky-check lanes (test_name = ''). 6 runs where the last recorded output is the preparation's own tpcds table listing, at 9013-9055 s (the whole job budget), plus the 2 bounded ones after #115585 at 4365 s and 4513 s. All 8 are Stateless tests (amd_tsan, flaky check), and the same two predicates over every other Stateless tests (% lane return nothing.


Workflow [PR]
Sync PR [sync-upstream/pr/117997]

Version info

  • Merged into: 26.9.1.1367 (included in 26.9 and later)

The `Stateless tests (amd_tsan, flaky check)` job livelocks while loading the
stateful fixture. The statement that never returns is

  INSERT INTO test.hits_s3 SELECT * FROM test.hits

The server logs normally for about 35 seconds, then emits nothing for about an
hour; `--max_execution_time 1800` never fires, `SYSTEM FLUSH LOGS` returns
SOCKET_TIMEOUT after its full 300 s, and `clickhouse stop` fails, so the process
has to be killed for a core. The statement is terminated at its bound and the job
fails without uploading a report, which discards the entire 50x re-run signal
that check exists to produce.

The flaky check is the only lane that arms ThreadFuzzer, and it arms it for the
whole server lifetime: `functional_tests.py` appends the fuzzer config during
INSTALL, so `THREAD_FUZZER_CPU_TIME_PERIOD_US=1000` is already in the server's
environment when it starts. The `ThreadFuzzer` constructor then self-arms a
process-wide `setitimer(ITIMER_PROF)` plus a SIGPROF handler, and nothing in this
lane ever stops it. `ITIMER_PROF` bills process CPU, so with hundreds of threads
the signal rate is roughly one per millisecond of aggregate CPU.

Under ThreadSanitizer every signal delivery enters `CallUserSignalHandler`, which
takes a per-thread sanitizer slot before dispatching, and the deliveries that
reach the fuzzer's handler sleep inside it and then re-attach a slot. TSan has
255 usable slots against the 684 live threads seen in the thread dump from a
wedged job, so threads block in `FindSlotAndLock` waiting for a slot held by a
thread that is itself blocked in a signal handler. 576 of those 684 threads are
stopped on exactly that, and no thread in the dump is running ClickHouse code,
which is why nothing logs, no timeout fires and no query is answered.

`ThreadFuzzer.cpp` already compiles its `pthread_mutex_*` injection out under
`THREAD_SANITIZER`, and the dump confirms that half is inert. The SIGPROF path
sits outside every sanitizer guard and is the only live mechanism there.

Nothing asserts anything about the fixture load, so fuzzing it buys no
race-detection signal while being able to discard the whole job's signal. This
stops the fuzzer for the duration of `prepare_stateful_data` and starts it again
immediately afterwards, in the flaky check only. It is the same scoping the
stress runner already applies to this very statement: `stress_runner.sh` exports
the same fuzzer environment, starts the server, runs `SYSTEM STOP THREAD FUZZER`,
and only then creates and loads `test.hits_s3`.

Both new statements sit inside the prep script, so they inherit its `set -e`, its
ERR trap and its per-statement `timeout` bound; no new error handling is added.
Re-arming restores the previous state exactly rather than approximately, because
the constructor's arming condition and `start()`'s are the same predicate.

For every other lane the flag is 0 and both guards are inert: rendering the prep
script with the flag off and executing it against a stub client produces an argv
log byte-identical to the one master's rendering produces.

Two things this deliberately does not change. `SYSTEM STOP THREAD FUZZER` clears
a flag but leaves the SIGPROF timer armed, so the cost of delivering the signal
is not removed, only the sleeping inside the handler. And the underlying
interaction between a signal-driven fault injector and the sanitizer's slot table
stays latent for any future phase that runs more threads than there are slots.
The comment added beside `stop_thread_fuzzer=is_flaky_check` justified the fix
rather than the code: its second and third lines described the slot exhaustion
that motivated the change, so a reader had to go to `git blame` to make sense of
them. It also named the sanitizer, while the flag is not sanitizer-conditional -
it is set for all five flaky lanes, including the debug and binary ones, where
the fuzzer costs the same fixture load 33x and 23x with no sanitizer involved.

The replacement states two standing properties of the code instead: that this
lane is the only one that arms the fuzzer, and that the fixture load is setup
rather than a test, which is why stopping the fuzzer across it loses no signal.
The comment I added in 0d48000, and that commit's own message, claimed
the flaky check is the only lane that arms `ThreadFuzzer`. That is wrong
repo-wide, and 0d48000 refutes itself further down by describing the
stress runner doing the same thing: `tests/docker_scripts/stress_runner.sh` arms
the fuzzer unconditionally at :21-23 and stops it at :96, and
`tests/integration/helpers/cluster.py` arms it per instance on request
(`DEFAULT_THREAD_FUZZER_SETTINGS` at :113, applied at :640 under
`enable_thread_fuzzer`).

The narrower claim is true, and it is the one that justifies the gate: of the
lanes this job runs, only the flaky check arms the fuzzer, because
`enable_thread_fuzzer_config` is appended only under `if is_flaky_check:`
(`ci/jobs/functional_tests.py:985-986`) and that is its sole caller. The comment
now states that.

I also reformatted the `prepare_stateful_data` signature to `black` output, so
the parameter added by 0d48000 does not leave a formatting deviation
inside this change.

Report for the failure this addresses:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110321&sha=2def28ac1fbdc8166d4e6c37c00ab830b4248148&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29
ClickHouse#110321
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 4, 2026
@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

Reviewed before publication: my own cold pass plus an independent model pass over the diff.

This reverses something I said. On 2026-08-31, on #110321, I reported that I had tried
bracketing the fixture load with SYSTEM STOP THREAD FUZZER and withdrew it, on three grounds.
Rather than leave that contradiction sitting there, what changed:

  1. The 1.76x I quoted was measured on my own machine, where the wedge never reproduced at all
    (3 arms, worst log silence 1 s against CI's ~62 minutes). Read from CI's own job logs at one
    commit, the fuzzed amd_tsan, flaky check never finishes the statement, while the unfuzzed
    amd_tsan lane finishes it in 217 s on the same instance type, with the same
    max_insert_threads=4 and the same row count.
  2. I said the pthread wrappers are compiled out under TSan. They are, and that is precisely
    why the fuzzer looked inert to me: the live path is the SIGPROF timer, which sits outside
    every sanitizer guard.
  3. I did not want to perturb the only occurrences before they could be diagnosed. Collect the full diagnostics when a stateless job fails during setup #117294 merged
    yesterday, so those runs now keep their cores and thread dumps.

Two limitations worth stating rather than leaving to be found. The wedge itself did not reproduce
locally (3 arms at 732-878 live threads with the fuzzer measurably active, all completed), so the
attribution rests on the same-commit lane comparison in the description, not on a local A/B. And
this PR changes no test file, so the five flaky lanes will skip and its own CI will not execute
the two new statements; the byte-identical argv-log proof and the re-arm measurement stand in
for that.

The last commit is comment text and a signature reformat only. I checked it is inert (ruff,
py_compile, and the rendered script's argv-log checksums unchanged on all arms) instead of
re-running the full pre-publication review over it.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5ac8517]

Summary: ✅


AI Review

Summary

This PR brackets prepare_stateful_data with SYSTEM STOP THREAD FUZZER / SYSTEM START THREAD FUZZER only in the functional-test flaky lane. The wiring stays scoped to is_flaky_check, preserves the previous behavior for every other prepare_stateful_data caller, and matches the current ThreadFuzzer lifecycle; I did not find a correctness issue in the current diff.

Missing context / blind spots
  • ⚠️ The PR's build/test matrix is still in progress, so this review is based on the current code, the existing PR discussion, and a local py_compile sanity check rather than a completed run of the modified flaky lane.
Final Verdict

✅ No review findings at the current head.

LLVM Coverage Report

⚠️ No coverage measurement for commit 5ac8517: incomplete coverage measurement: 16 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_ft_2.profdata, LLVM_COVERAGE_FILE_ft_3.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_parallel_2.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_parallel_3.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_sequential_1.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_sequential_2.profdata, LLVM_COVERAGE_FILE_ft_s3_async_sequential.profdata, LLVM_COVERAGE_FILE_ft_s3_sequential.profdata, LLVM_COVERAGE_FILE_it_1.profdata, LLVM_COVERAGE_FILE_it_2.profdata, LLVM_COVERAGE_FILE_it_3.profdata, LLVM_COVERAGE_FILE_it_4.profdata, LLVM_COVERAGE_FILE_it_5.profdata, LLVM_COVERAGE_FILE_it_6.profdata, LLVM_COVERAGE_FILE_it_7.profdata, LLVM_COVERAGE_FILE_it_8.profdata.

@groeneai

groeneai commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? Of the lanes that run functional_tests.py only the flaky check arms ThreadFuzzer, and it arms it for the whole server lifetime, so the stateful fixture load runs fuzzed although nothing asserts on its interleaving: under TSan each SIGPROF delivery takes one of 255 thread slots before dispatch and one that sleeps in the handler re-attaches one, which is what wedges INSERT INTO test.hits_s3 SELECT * FROM test.hits. This stops the fuzzer across prepare_stateful_data and starts it again immediately after, in that lane only.

@PedroTadim

Copy link
Copy Markdown
Member

cc @alexey-milovidov

@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into ClickHouse:master with commit 336d7d2 Sep 13, 2026
174 of 175 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants