Skip to content

Do not run the server-side AST fuzzer on the stress harness's own queries - #113248

Closed
alexey-milovidov wants to merge 24 commits into
masterfrom
fix-stress-fault-injection-verify-retry
Closed

alexey-milovidov wants to merge 24 commits into
masterfrom
fix-stress-fault-injection-verify-retry

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

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

The stress test aborts with Test script failed before running a single test:

Error on processing query: Timeout exceeded while receiving data from server. Waited for 15 seconds, timeout is 15 seconds.
(query: SELECT value FROM system.server_settings WHERE name = 'cannot_allocate_thread_fault_injection_probability')
...
subprocess.CalledProcessError: ... returned non-zero exit status 159.

The fail-close verification in install_thread_pool_fault_injection (added in #104782) ran a single clickhouse client query with --receive_timeout=15 and no retry, so one slow answer killed the whole job. The first commit retries it, mirroring call_with_retry, keeping the fail-close semantics: persistent failure or a zero probability still aborts the run.

Retrying alone is not enough, because the server is not slow. The stress profile (stress_tests.lib) enables the server-side AST fuzzer for the default user with ast_fuzzer_runs=5 and ast_fuzzer_any_query=true, and that also applies to the maintenance queries of the harness itself. The fuzzer runs as a query-finish callback, so the connection thread executes the five mutated follow-up queries before the response completes. In Stress test (arm_release) on #113224 (#113224) the verification query read its 439 rows in 67 ms and the handler returned after 16.3 s, past the client's 15-second receive_timeout:

21:12:45.393 executeQuery: Read 439 rows, 131.72 KiB in 0.067 sec.
21:12:45.395 ASTFuzzer: Fuzzed query: SELECT value FROM system.server_settings WHERE name = ...
             ... 5 fuzzed follow-up queries ...
21:13:01.597 TCPHandler: Processed in 16.274 sec.

Every one of the five queries the fuzzer fired on in that run was the harness's own: the SYSTEM RELOAD CONFIG and the verification query of stress.py (11.3 s and 16.3 s in the connection thread), the two SELECT 1 readiness probes and the SYSTEM STOP DISTRIBUTED SENDS of stress_tests.lib. No test query was fuzzed, because clickhouse-test runs are already started with ast_fuzzer_runs=0.

The second commit pins ast_fuzzer_runs=0 on the harness's own queries, in stress.py and in stress_tests.lib. That is what clickhouse-test already does for its infrastructure queries (clickhouse_execute_http) and what stress.py already did for the smoke check and the hung check. An explicit value on the command line is marked changed even though it equals the default, so the client sends it and it overrides the profile.

Besides the timeouts this also stops two hazards that ast_fuzzer_any_query made possible:

  • A fuzzed DETACH DATABASE / KILL QUERY from prepare_for_hung_check, or a fuzzed SYSTEM STOP DISTRIBUTED SENDS during shutdown, running some other statement.
  • Fuzzed copies of a system.processes query showing up in the very processlist the hung check is about to inspect.

A fuzzed readiness probe can also burn most of the 30-second receive_timeout of start_server, which reports Cannot start clickhouse-server for a server that is up.

Related: #109496
Related: #113224
Related: #104782

…imeout

The fail-close verification in `install_thread_pool_fault_injection` ran a
single `clickhouse client` query with `--receive_timeout=15`. Under
`THREAD_FUZZER_*` injection the server can be too sluggish to answer even a
trivial `system.server_settings` query within 15 seconds right after
`SYSTEM RELOAD CONFIG`, so the client exited with `TIMEOUT_EXCEEDED` and the
whole stress run aborted with 'Test script failed' before running any tests.
Seen in https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109496&sha=cdcd7ba5f5e3f77ab23cf617534b6bb30668907e&name_0=PR&name_1=Stress%20test%20%28arm_release%29
on #109496.

Retry the verification query up to 5 times, keeping the fail-close semantics:
persistent failure or a zero probability still aborts the run.

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1daee26]


AI Review

Summary

This PR propagates NO_AST_FUZZER through the stress and AST-fuzzer harness queries, keeps the log-export teardown fail-close, and preserves compatibility with previous-release clients by allowing an empty opt-out when the old client does not support ast_fuzzer_runs. I rechecked the current head against the full diff, prior review-thread discussion, and the green PR CI report, and I did not find any remaining blocker or major issue.

Final Verdict

✅ No blocking or major issues found in the current diff.

The stress profile enables the server-side AST fuzzer for the `default` user with
`ast_fuzzer_runs=5` and `ast_fuzzer_any_query=true`, and that also applies to the
maintenance queries the harness itself runs.

The fuzzer runs as a query-finish callback, so the connection thread executes the
five mutated follow-up queries before the response completes. In
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113224&sha=297082adba654b8bafac191c6c61b5023bcc76ef&name_0=PR&name_1=Stress%20test%20%28arm_release%29
(#113224) the verification query of
`install_thread_pool_fault_injection` read its 439 rows in 67 ms and the handler
then returned after 16.3 s:

    executeQuery: Read 439 rows, 131.72 KiB in 0.067 sec.
    ASTFuzzer: Fuzzed query: SELECT value FROM system.server_settings WHERE name = ...
    ...
    TCPHandler: Processed in 16.274 sec.

which is past the client's `--receive_timeout=15`, so the client exited with
`TIMEOUT_EXCEEDED` (code 159) and the whole job failed with "Test script failed"
before a single test ran. The server was not slow; the retry added in the previous
commit only re-rolls the same dice.

All five queries the fuzzer fired on in that run were the harness's own: the
`SYSTEM RELOAD CONFIG` and the verification query of `stress.py` (11.3 s and
16.3 s), the two `SELECT 1` readiness probes and the `SYSTEM STOP DISTRIBUTED
SENDS` of `stress_tests.lib`. No test query was fuzzed, because
`clickhouse-test` runs are already started with `ast_fuzzer_runs=0`.

Pin `ast_fuzzer_runs=0` on the harness's queries, which is what
`clickhouse-test` does for its infrastructure queries and what `stress.py`
already did for the smoke check and the hung check. An explicit value on the
command line is marked `changed` even though it equals the default, so the client
sends it and it overrides the profile.

Besides the timeouts this also stops two things that `ast_fuzzer_any_query` made
possible: a fuzzed `DETACH DATABASE` / `KILL QUERY` from `prepare_for_hung_check`
or a fuzzed `SYSTEM STOP DISTRIBUTED SENDS` during shutdown running some other
statement, and fuzzed copies of a `system.processes` query showing up in the very
processlist the hung check is about to inspect.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov alexey-milovidov changed the title Stress test: retry the fault-injection verification query on client timeout Do not run the server-side AST fuzzer on the stress harness's own queries Aug 5, 2026
Comment thread tests/docker_scripts/stress_tests.lib Resolved

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix.

@alexey-milovidov alexey-milovidov self-assigned this Aug 5, 2026
The previous commit stopped at `stress.py` and `stress_tests.lib`, so the invariant
"the harness does not fuzz its own queries" was not visible in the entrypoints.
Thread `NO_AST_FUZZER` through every server query of `stress_runner.sh`,
`upgrade_runner.sh` and the `create_tpcds.sh` / `create_tpch.sh` helpers as well.

The fuzzer profile is installed by `configure_limits`, not by `configure` (only
`stress_runner.sh` calls it, after the dataset setup), so today those queries are not
fuzzed yet - but nothing in the scripts says so, and moving `configure_limits` earlier
would silently reintroduce the failure mode. The comment in `stress_tests.lib` is
corrected accordingly.

`NO_AST_FUZZER` is now exported, so the `create_*.sh` helpers inherit it; they read it
as `${NO_AST_FUZZER:-}` because `clickhouse_proc.py` also runs them outside the stress
harness.

`install_packages` re-derives the option from the installed binary: `ast_fuzzer_runs`
exists only since 26.2, and the upgrade check installs the previous release, whose
client would reject an unknown command-line option and fail every harness query. The
probe only ever removes the option when the client explicitly reports the setting as
absent, so a failing probe cannot silently re-enable fuzzing of our own queries.
alexey-milovidov and others added 2 commits August 9, 2026 11:36
…_replication`

The `stop_log_exports` wrappers in `clickhouse_proc.py` and
`sqlstorm_test.py` ran a plain `clickhouse-client --query "SYSTEM FLUSH
LOGS"` before calling `setup_log_cluster.sh --stop-log-replication`,
outside the `NO_AST_FUZZER` plumbing. Move the flush into
`stop_logs_replication` so the whole log-export lifecycle inherits the
script's existing `${NO_AST_FUZZER:-}` guard and the "the harness's own
queries are not fuzzed" contract is covered in one place.

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov pushed a commit to UberDever/ClickHouse that referenced this pull request Aug 9, 2026
The `TTLDropMerge` in Case 2 produces an empty part, and the cleanup
thread removes empty parts in the background (the `remove_empty_parts`
MergeTree setting is enabled by default). When that removal wins the
race against the test's `SELECT projections FROM system.parts WHERE ...
active` check, the query returns zero rows instead of the expected `[]`
line. Set `remove_empty_parts = 0` on the Case 2 table so the empty
part deterministically stays active for the check.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=113248&sha=0f4ecdf5bcb488588e9d664687d1b482d67d62f9&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%201%2F3%29
PR: ClickHouse#113248

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov and others added 2 commits August 9, 2026 23:59
…cluster.sh`

The dedicated AST fuzzer job installs `query-fuzzer-tweaks-users.xml`
(`ast_fuzzer_runs=5`, `ast_fuzzer_any_query=true`) in `run-fuzzer.sh` and then
calls `clickhouse_proc.py logs_export_start` without exporting `NO_AST_FUZZER`,
so the local-server queries of this shared helper (`SYSTEM FLUSH LOGS`, the
`BUILD_TYPE` probe, `SHOW TABLES FROM system`, `SHOW CREATE TABLE`) were still
running under the fuzzer profile there. Derive the opt-out centrally in the
helper instead of relying on every caller: `NO_AST_FUZZER=${NO_AST_FUZZER-"--ast_fuzzer_runs=0"}`.
Plain `-` (not `:-`) preserves the deliberate empty opt-out that
`install_packages` sets for a client that predates the `ast_fuzzer_runs`
setting and would reject the unknown option.

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov and others added 3 commits August 10, 2026 21:07
Moving the flush into `stop_logs_replication` also turned it from a required
step into a warning-only one, so `stop_log_exports` would report success while
silently dropping the final buffered system-log rows. Drop the
`|| echo WARNING` so the script's `set -e` propagates the failure to the
callers, as it did when they ran the flush themselves, while keeping the query
under the `NO_AST_FUZZER` guard.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…jection-verify-retry

Conflict in `ci/jobs/scripts/stress/stress.py`: master's `6fe5a48b7b2a`
("Fix stress test failures due to internal queries was fuzzed") landed the same
root-cause fix for `make_query_command`, hardcoding `--ast_fuzzer_runs=0` inline
(and leaving a stray trailing comma that turns the `-> str` return value into a
tuple). Kept this branch's `{NO_AST_FUZZER}`, which is the single place the
option is defined and documented in this script and is what every other query
here already uses.
The runners export `NO_AST_FUZZER`, and `install_packages` deliberately sets it
to an empty string for a client that predates the `ast_fuzzer_runs` setting and
would reject the unknown command-line option. The upgrade check runs
`stress.py` with exactly such a previous-release client
(`upgrade_runner.sh` installs `previous_release_package_folder`, then invokes
`stress`), so hardcoding the option here would turn every query this script
runs into a hard failure once the previous release predates 26.2. Read the
variable with a default so the empty opt-out is honoured, and keep the
`argv`-form call sites free of an empty argument.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and resolved a conflict in ci/jobs/scripts/stress/stress.py: 6fe5a48b7b2a ("Fix stress test failures due to internal queries was fuzzed", from #113927) landed the same root-cause fix for make_query_command independently today, hardcoding --ast_fuzzer_runs=0 inline. I kept this branch's {NO_AST_FUZZER}, which is the single documented definition used by every other query in the script.

Two notes on that master commit, both handled here:

  • it left a stray trailing comma ("--ast_fuzzer_runs=0",) inside the return (...), so make_query_command — annotated -> str — actually returned a 1-tuple; it only worked by accident because subprocess with shell=True accepts a sequence and uses args[0] as the command. The merged version has no comma.
  • hardcoding the option in stress.py is a hazard for the upgrade check, which runs this script with the previous release client (upgrade_runner.sh installs previous_release_package_folder, then invokes stress): a client that predates ast_fuzzer_runs (26.2) rejects the unknown command-line option and every harness query fails. stress.py now reads NO_AST_FUZZER from the environment with a default, so it honours the empty opt-out that install_packages sets for such a client.

Also addressed the AI Review Major: the final SYSTEM FLUSH LOGS in stop_logs_replication is fail-close again (set -e propagates it to stop_log_exports), while staying under the NO_AST_FUZZER guard.

alexey-milovidov and others added 4 commits August 11, 2026 17:04
The dedicated AST fuzzer job installs `query-fuzzer-tweaks-users.xml`
(`ast_fuzzer_runs=5`, `ast_fuzzer_any_query=true`) and then issues its own
plain `clickhouse-client` probes: the readiness loops, the `IS_ASAN`
build-options query, the gdb-attach connectivity check, the restart
liveness check, the post-run liveness probe loop, and the `stop_server` /
`SHOW PROCESSLIST` diagnostics. Each of those triggered five mutated
follow-up queries in the connection thread, which can burn the probe's
`receive_timeout` or execute a mutated statement before fuzzing starts.

Export `NO_AST_FUZZER="--ast_fuzzer_runs=0"` in `run-fuzzer.sh` and thread
it through every harness-owned query, mirroring `stress_tests.lib`. The
actual fuzzer client invocation deliberately does not use it. This job
always runs the freshly built binary, so the pre-26.2 client opt-out of
`install_packages` does not apply here.

Co-Authored-By: Claude Fable 5 <[email protected]>
…jection-verify-retry

# Conflicts:
#	ci/jobs/scripts/functional_tests/setup_log_cluster.sh
#	ci/jobs/scripts/stress/stress.py
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Closing as already integrated: the current PR head 1daee26914723f2246184ea2718653c8403e718b is an ancestor of master (2409fdca32a84bbc38cd8658ea22b7f2568f8e25). All review feedback has been addressed in the included commits.

pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Sep 26, 2026
…ness's own queries

After a clean fuzz run (`Fuzzer exit code is 143`), the post-fuzz liveness
probe `clickhouse-client --handshake_timeout_ms=30000 --receive_timeout=5
--query 'SELECT 1'` sometimes never returns. status.tsv is then never
written, praktika kills the job at its 18000 s timeout before any artifact
is uploaded, and the job reports a bare ERROR with no server log. Five such
runs in 45 days: PR ClickHouse#112304 (2026-08-18), PR ClickHouse#98670 (2026-08-19), PR ClickHouse#115530
(2026-08-20), true master 9816d0a `AST fuzzer (amd_release, oracle)`
(2026-09-24) and PR ClickHouse#119237 `AST fuzzer (amd_debug, targeted,
old_compatibility)` (2026-09-25). Only the last one printed the `1`.

Two harness defects make the probe unbounded.

(a) The probe is itself fuzzed on the server. query-fuzzer-tweaks-users.xml
sets ast_fuzzer_runs=5 and ast_fuzzer_any_query=true on the `default`
profile, and no harness-owned client call opted out. The server runs the
mutated copies in a query-finish callback, and TCPHandler calls
io.onFinish() after sending the data and before EndOfStream, so a fuzzed
follow-up that does not finish holds the reply open after the `1` was
printed. The same pin was part of ClickHouse#113248, which was closed as already
integrated, but its run-fuzzer.sh half never reached master. The stress
harness (ClickHouse#114127), the log export (ClickHouse#117996) and tests/clickhouse-test
already pin it.

(b) --receive_timeout does not bound the probe either. On a receive
timeout ClientBase::receiveResult only records TIMEOUT_EXCEEDED and cancels
the query; from then on it polls the connection until the server sends a
packet, with no bound. A server whose connection thread never gets back to
the socket holds the probe forever, which is what the four runs that
printed nothing show.

Pin --ast_fuzzer_runs=0 on every harness-owned client call through one
variable; the fuzzer's own client stays unpinned. Run the two post-fuzz
probes (the restart liveness check and the probe loop) under
`timeout --signal TERM --kill-after=10 60`. A probe killed by timeout
(rc 124, or 137 after the kill) is counted like the client's own
"Timeout exceeded while", so a server that stops answering reaches the
existing "treating server as hung" verdict after 12 retries (about
14 minutes) and the job keeps its logs. 60 s covers the probe's own worst
case (30 s handshake, 5 s receive timeout, the cancel round trip) with room
for a slow sanitizer server. The fallback branch now prints the probe's
exit code instead of the last grep's.

The pre-fuzz probes are not wrapped: the check after attaching gdb waits
for gdb to load debug info on purpose, and the server is fresh there.

One server-side hang the fuzzer produces, a self-deadlock when one query
builds two system.stack_trace sources, is fixed separately in ClickHouse#120216.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants