Skip to content

Cap max_threads in the AST fuzzer to avoid server-liveness hangs - #109256

Merged
PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/fuzzer-cap-max-threads
Jul 8, 2026
Merged

PedroTadim merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/fuzzer-cap-max-threads

Conversation

@groeneai

@groeneai groeneai commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

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):

...

Description

The AST fuzzer mutates query settings freely, and a fuzzed max_threads in the tens of thousands (observed: 65535) makes a single query request far more pipeline threads than the global thread pool provides (max_thread_pool_size defaults to 10000). The pool saturates (CANNOT_SCHEDULE_TASK: no free thread, threads=10000, jobs=10000), which:

  • starves the run-fuzzer.sh server-liveness probe: a fresh connection's SELECT 1 cannot get a thread, so the probe blocks and times out; and
  • delays max_execution_time cancellation, because the cancellation-check machinery itself needs threads it cannot get.

On a loaded amd_debug runner this stretches to minutes. The liveness loop counts 12 probe timeouts and declares the server hung, the watchdog kills it, and the job fails with Lost connection to server even though the server never crashed and produced no LOGICAL_ERROR / sanitizer report. Seen across ~11 unrelated PRs in 30 days (0 on master).

This adds a max_threads <max>128</max> constraint alongside the existing max_execution_time / max_memory_usage caps in the fuzzer users profile. A fuzzed value above the cap now yields a clean SETTING_CONSTRAINT_VIOLATION (an expected error the fuzzer already tolerates and continues past) instead of hanging the server. 128 stays well below the 10000-thread pool so a single query cannot saturate it, while still exercising high parallelism. The same constraint is mirrored into the stress-path AST-fuzzer profile (tests/docker_scripts/stress_tests.lib), which also enables ast_fuzzer_runs, so every server-side fuzzer profile gets the cap.

Reproduced locally on a debug build (Build ID 6d09f948f426): with the current profile a fuzzed max_threads=65535 query hits CANNOT_SCHEDULE_TASK: threads=10000, jobs=10000 and delays max_execution_time=10 cancellation to 24s; with the constraint the same query returns SETTING_CONSTRAINT_VIOLATION and the SELECT 1 liveness probe answers in 0s. A 30-run AST-fuzzer smoke pass against the fixed profile leaves the server alive.

Example CI failure (PR #108676): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108676&sha=ca7d8c5328a48a03641468706660084bf1ea9765&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29

Version info

  • Merged into: 26.7.1.651 (included in 26.7 and later)

The AST fuzzer mutates query settings freely, and a fuzzed max_threads
in the tens of thousands (observed: 65535) makes a single query request
far more pipeline threads than the global thread pool provides
(max_thread_pool_size defaults to 10000). The pool saturates
(CANNOT_SCHEDULE_TASK: no free thread, threads=10000, jobs=10000), which:

  - starves the run-fuzzer.sh server-liveness probe: a fresh connection's
    SELECT 1 cannot get a thread, so the probe blocks and times out; and
  - delays max_execution_time cancellation, because the cancellation-check
    machinery itself needs threads it cannot get.

On a loaded amd_debug runner this stretches to minutes. The liveness loop
counts 12 probe timeouts and declares the server hung, the watchdog kills
it, and the job fails with "Lost connection to server" even though the
server never crashed and produced no LOGICAL_ERROR / sanitizer report.
Seen across ~11 unrelated PRs in 30 days (0 on master).

Add a max_threads <max>256</max> constraint alongside the existing
max_execution_time / max_memory_usage caps in the fuzzer users profile.
A fuzzed value above the cap now yields a clean SETTING_CONSTRAINT_VIOLATION
(an expected error the fuzzer already tolerates and continues past) instead
of hanging the server. 256 stays well below the 10000-thread pool so a
single query can't saturate it, while still exercising high parallelism.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a debug build with the current fuzzer profile, SELECT ... FROM numbers_mt(2147483646) SETTINGS max_threads=65535 deterministically hits CANNOT_SCHEDULE_TASK: no free thread, threads=10000, jobs=10000 and, for a scanning variant, delays max_execution_time=10 cancellation to ~24s.
b Root cause explained? Yes. Fuzzed max_threads (65535) >> max_thread_pool_size (10000). One query saturates the global thread pool, so (1) a fresh-connection SELECT 1 liveness probe cannot get a thread and blocks/times out, and (2) max_execution_time cancellation is delayed because its check machinery also needs threads. On a loaded amd_debug runner the probe starvation stretches to minutes; the liveness loop declares the server hung and the watchdog kills it -> "Lost connection to server", no crash / no LOGICAL_ERROR.
c Fix matches root cause? Yes. Caps max_threads at 256 via a <constraints> entry (same mechanism as the existing max_execution_time/max_memory_usage caps), directly preventing a single query from saturating the 10000-thread pool.
d Test intent preserved / new tests added? Yes. The fuzzer still exercises high parallelism (max_threads up to 256); only pathological pool-saturating values are blocked, and the fuzzer already tolerates the resulting SETTING_CONSTRAINT_VIOLATION and continues. No test is weakened.
e Both directions demonstrated? Yes. Without the constraint: fuzzed query saturates the pool / delays cancellation to 24s. With the constraint: the same max_threads=65535 query returns a clean SETTING_CONSTRAINT_VIOLATION and the SELECT 1 probe answers in 0s; a 30-run AST-fuzzer smoke pass leaves the server alive.
f Fix is general across code paths? N/A (CI fuzzer-config fix, not a code bug).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (CI fuzzer-config fix, not a code bug). The cap applies to any query regardless of the fuzzed max_threads value.
h Backward compatible? (maintainer-approved exception only) N/A. CI-only config; does not affect server defaults or user-facing behavior.
i Invariants and contracts preserved? N/A (CI fuzzer-config fix, not a code bug).

Session id: cron:clickhouse-worker-slot-0:20260703-044400

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @PedroTadim — could you review this? It caps max_threads at 256 via a constraint in the AST fuzzer users profile (same mechanism as the existing max_execution_time/max_memory_usage caps). A fuzzed max_threads=65535 otherwise saturates the 10000-thread global pool, starving the run-fuzzer.sh liveness probe and hanging the server until the watchdog kills it ("Lost connection to server", no crash). Follow-up to the liveness-probe hardening in #108582.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aec5d9b]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_debug) FAIL
Logical error: 'Inconsistent AST formatting: the original AST: (STID: 1941-26fa) FAIL cidb, issue

AI Review

Summary

This PR caps max_threads to 128 in both server-side AST-fuzzer user profiles so fuzzed SETTINGS max_threads = ... values cannot monopolize the global thread pool and trip the harness liveness probe. I checked the current diff, the prior discussion, and the remaining ast_fuzzer_runs surfaces that matter for this rollout, and I did not find a remaining correctness or coverage gap in the current PR head.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 3, 2026
The stress harness enables the same server-side AST fuzzer
(ast_fuzzer_runs=5) via configure_limits in tests/docker_scripts/stress_tests.lib,
which writes stress_test_tweaks-users.xml. That profile did not carry the
max_threads constraint, so a fuzzed max_threads in the tens of thousands could
still saturate the global thread pool in the real stress workload, causing the
same server-liveness hang this PR eliminates for the dedicated fuzzer job.

Mirror the max_threads <max>256</max> constraint into stress_test_tweaks-users.xml
so every ast_fuzzer_runs>0 profile is bounded. The smoke and hung checks in
stress.py already force ast_fuzzer_runs=0, so they need no cap.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jul 3, 2026
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Re-posting the pre-PR validation gate after 7f03569 (mirror the max_threads cap into the stress AST-fuzzer path).

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the original bug: clickhouse-client -q "SELECT sleep(3) SETTINGS max_threads = 65535" against a server with max_thread_pool_size=10000 saturates the pool with CANNOT_SCHEDULE_TASK and starves the SELECT 1 liveness probe. Same profile mechanism (ast_fuzzer_runs=5 + no max_threads constraint) is what stress_test_tweaks-users.xml generated.
b Root cause explained? A fuzzed max_threads in the tens of thousands makes one query request more pipeline threads than the global pool holds, saturating it. The run-fuzzer.sh / stress liveness probe cannot run, max_execution_time cancellation is delayed, the watchdog kills the server and the job fails "Lost connection to server" with no crash. The dedicated fuzzer job was fixed in this PR; the stress path enables the identical server-side AST fuzzer via configure_limits but its constraints block lacked the cap.
c Fix matches root cause? Yes. It bounds the exact setting (max_threads <max>256</max>) in the second profile that enables the fuzzer, so the fuzzer can never request more threads than the pool can serve. Not a symptom guard.
d Test intent preserved / new tests added? The stress AST fuzzer still runs (ast_fuzzer_runs=5 unchanged); only max_threads is clamped, same as the dedicated job. No test weakened. This is CI-harness config; the observable behavior is a clean SETTING_CONSTRAINT_VIOLATION instead of a pool-saturation hang.
e Both directions demonstrated? The generated stress_test_tweaks-users.xml was extracted from the heredoc and validated: without the change the <constraints> block has no max_threads (fuzzer can pick 65535); with it, the constraint is present and well-formed (verified via XML parse). The setting-constraint mechanism itself is already exercised by the identical caps in this same file (max_execution_time, max_memory_usage).
f Fix is general across code paths? Yes. Enumerated every ast_fuzzer_runs site in the repo: the dedicated fuzzer XML (capped by this PR), stress_test_tweaks-users.xml (capped now), and the two stress.py sites which force ast_fuzzer_runs=0. No ast_fuzzer_runs>0 profile is left uncapped.
g Fix generalizes across inputs? N/A (CI-config setting cap, not a code bug). The constraint clamps all fuzzed values above 256 regardless of query/session/URL origin.
h Backward compatible? N/A (CI test-harness users profile only; no user-facing setting default, format, or data change).
i Invariants and contracts preserved? Yes. bash -n on the lib passes and the generated XML is well-formed; the new constraint sits inside the existing <constraints> block alongside the sibling caps, preserving the profile structure.

Session id: cron:clickhouse-worker-slot-9:20260703-074200

Per reviewer request: 128 still comfortably exceeds any realistic single
query thread count and stays far below the 10000-thread global pool, so
one fuzzed query cannot saturate it. Applied to both the dedicated
fuzzer profile and the mirrored stress-path constraint.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Reposting the pre-PR validation gate after the 256 -> 128 cap adjustment (applied to both the dedicated fuzzer profile and the mirrored stress-path constraint).

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A fuzzed SETTINGS max_threads = 65535 query deterministically hits CANNOT_SCHEDULE_TASK: threads=10000, jobs=10000 and stalls max_execution_time cancellation (24s on a debug build), starving the SELECT 1 liveness probe.
b Root cause explained? A fuzzed max_threads in the tens of thousands requests more pipeline threads than the 10000-thread global pool provides. The pool saturates, so a fresh connection's SELECT 1 cannot get a thread and the liveness probe times out, and cancellation itself is starved. The liveness loop declares the server hung and the watchdog kills it, with no crash or LOGICAL_ERROR.
c Fix matches root cause? Yes. The max_threads constraint bounds the fuzzed value far below the pool size so one query can no longer saturate it; over-cap values become a clean SETTING_CONSTRAINT_VIOLATION the fuzzer already tolerates. 128 (down from 256 per reviewer request) stays well below 10000 while still exceeding any realistic single-query thread count.
d Test intent preserved / new tests added? Yes. This is a CI fuzzer-harness config change; it neuters no test. The fuzzer still exercises high parallelism (up to 128 threads). Validated by XML well-formedness of both generated profiles plus the earlier 30-run AST-fuzzer smoke pass.
e Both directions demonstrated? Yes. Without the constraint the fuzzed max_threads=65535 query hangs (CANNOT_SCHEDULE_TASK, cancellation delayed to 24s); with the constraint it returns SETTING_CONSTRAINT_VIOLATION and the probe answers in 0s. 65535 > 128 as before 65535 > 256, so lowering the cap keeps the same behavior.
f Fix is general across code paths? Yes. The same server-side AST fuzzer runs in two places, and both now carry the cap: the dedicated fuzzer job (query-fuzzer-tweaks-users.xml) and the stress path (stress_test_tweaks-users.xml generated by tests/docker_scripts/stress_tests.lib, which enables ast_fuzzer_runs=5). Enumerated all ast_fuzzer_runs sites; the only others force ast_fuzzer_runs=0, so no fuzzer-enabled profile is left uncapped.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (CI fuzzer-profile setting cap, not a code bug).
h Backward compatible? (maintainer-approved exception only) N/A (CI-internal fuzzer harness profile; not a user-facing setting default or on-disk/wire format).
i Invariants and contracts preserved? N/A (config value change; bounds only the fuzzer's setting range, no server code path or invariant is touched).

Session id: cron:clickhouse-worker-slot-9:20260703-115000

@groeneai

groeneai commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — bf3bce9

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan) / Block structure mismatch in A stream (STID 0993-386d) chronic trunk logical error (32 hits / 26 unrelated PRs / 0 master, 30d; this PR only edits AST-fuzzer users-profile XML and cannot produce a block-structure mismatch) #107719 (ours, open) — Fix Block structure mismatch in UnionStep/IntersectOrExceptStep; umbrella #94517
Mergeable Check / PR rollup of the above owned via #107719
CH Inc sync — CH Inc sync (private, not actionable)

Session id: cron:our-pr-ci-monitor:20260703-140000

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai merge with master

@groeneai

groeneai commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

@PedroTadim merged master in (aec5d9b). No conflicts; only the two CI-config files differ from master and the max_threads=128 cap is intact in both profiles.

the server-liveness probe and delaying query cancellation. Cap it. -->
<max_threads>
<max>128</max>
</max_threads>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you move this to limit-recursion-settings.xml it's shared between all ast fuzzer runs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@groeneai can you do this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in follow-up #109755: moved the max_threads 128 cap into limit-recursion-settings.xml (cp'd into users.d by run-fuzzer.sh, clickhouse_proc.py, and stress_runner.sh), and removed the two duplicated copies from query-fuzzer-tweaks-users.xml and stress_tests.lib.

@PedroTadim
PedroTadim added this pull request to the merge queue Jul 8, 2026
Merged via the queue into ClickHouse:master with commit be929a3 Jul 8, 2026
173 of 175 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 8, 2026
subkanthi pushed a commit to subkanthi/ClickHouse that referenced this pull request Jul 8, 2026
…ngs.xml

Follow-up to ClickHouse#109256. That PR added a max_threads <max>128</max> constraint
in two places (query-fuzzer-tweaks-users.xml and the stress-path
stress_test_tweaks-users.xml heredoc in stress_tests.lib). Consolidate it into
limit-recursion-settings.xml, which is already cp'd into users.d by every
ast_fuzzer_runs entry point (run-fuzzer.sh, clickhouse_proc.py, stress_runner.sh),
so a single location covers the dedicated AST fuzzer and the stress test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…p-max-threads

Cap max_threads in the AST fuzzer to avoid server-liveness hangs
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ngs.xml

Follow-up to ClickHouse#109256. That PR added a max_threads <max>128</max> constraint
in two places (query-fuzzer-tweaks-users.xml and the stress-path
stress_test_tweaks-users.xml heredoc in stress_tests.lib). Consolidate it into
limit-recursion-settings.xml, which is already cp'd into users.d by every
ast_fuzzer_runs entry point (run-fuzzer.sh, clickhouse_proc.py, stress_runner.sh),
so a single location covers the dedicated AST fuzzer and the stress test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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 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.

3 participants