Skip to content

Cap recursion-controlling parser/AST settings in fuzzer and stress test - #108863

Merged
Algunenano merged 7 commits into
ClickHouse:masterfrom
Algunenano:cap-fuzzer-stress-recursion-settings
Jul 6, 2026
Merged

Algunenano merged 7 commits into
ClickHouse:masterfrom
Algunenano:cap-fuzzer-stress-recursion-settings

Conversation

@Algunenano

@Algunenano Algunenano commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

The query fuzzer and the stress test could run queries that build pathologically deep or large expressions, taking minutes to parse and format and tripping the hung check. For example:

SELECT formatQuery($$SELECT [[[[ ...20000... ]]]]$$)

run with max_parser_depth=100000000. The stress test ignores no-* build tags (see tests/clickhouse-test) and runs the fuzzer over every query, so a single test raising these settings is enough to hang the server under sanitizers.

The recursion constraints are moved out of query-fuzzer-tweaks-users.xml into a shared limit-recursion-settings.xml, installed by both the AST fuzzer and the stress runner. It caps max_ast_depth, max_parser_depth, max_parser_backtracks, max_ast_elements and max_expanded_ast_elements at their defaults via <max> (lowering is still allowed), so neither the fuzzer nor a test can raise them to values that build huge queries.

Seen in: https://s3.amazonaws.com/clickhouse-test-reports/PRs/108593/633f156999f8febe513b07e4334382a758e0a1ec/stress_test_amd_tsan/hung_check.log

Changelog category (leave one):

  • CI Fix or Improvement

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

Version info

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

The query fuzzer and stress test could run queries that build pathologically
deep/large expressions, taking minutes to parse and format and tripping the
hung check, e.g.:

    SELECT formatQuery($$SELECT [[[[ ...20000... ]]]]$$)

with `max_parser_depth=100000000`. The stress test ignores `no-*` build tags
(`tests/clickhouse-test`) and runs the fuzzer over every query, so a single
test setting these high is enough to hang the server under sanitizers.

Move the recursion constraints out of `query-fuzzer-tweaks-users.xml` into a
shared `limit-recursion-settings.xml` and install it in both the AST fuzzer and
the stress runner. It caps `max_ast_depth`, `max_parser_depth`,
`max_parser_backtracks`, `max_ast_elements` and `max_expanded_ast_elements` at
their defaults via `<max>` (lowering is still allowed), so neither the fuzzer
nor a test can raise them to values that build huge queries.

Seen in: https://s3.amazonaws.com/clickhouse-test-reports/PRs/108593/633f156999f8febe513b07e4334382a758e0a1ec/stress_test_amd_tsan/hung_check.log

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0139045]

Summary: ✅


AI Review

Summary

This PR moves the recursion-setting caps into a shared limit-recursion-settings.xml, installs that profile for both the AST fuzzer and the stress job, and pins max_parser_backtracks on the client path that compatibility can otherwise reopen. The standalone AST fuzzer path is covered now, but the stress path still has an uncapped client-side parser route through shell tests, so the main hung-check failure mode is not fully closed.

Findings

❌ Blockers

  • [tests/docker_scripts/stress_runner.sh:293] Copying limit-recursion-settings.xml into users.d only constrains the server session. clickhouse-test --stress-tests still executes shell tests, and those wrappers append their own client flags after CLICKHOUSE_CLIENT_OPT (tests/queries/shell_config.sh:36-38). tests/queries/0_stateless/04411_deep_nested_field_to_type.sh:22 and tests/queries/0_stateless/04412_deep_nested_literal_format.sh:19 both pass --max_parser_depth=100000000, so the client-side parser can still build the same 20k/30k-deep AST locally before the query reaches the server. That means the stress hung-check this PR is trying to eliminate is still reproducible from the shell-test path.
    Suggested fix: enforce the client-side parser cap in a way shell tests cannot override, or exclude the deep-recursion shell tests from --stress-tests.
Final Verdict

Status: ⚠️ Request changes
Minimum required action: close the remaining shell-test client path in stress, so 04411/04412 cannot raise max_parser_depth back to 100000000 and hang before the query reaches the constrained server.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 29, 2026
Comment thread tests/docker_scripts/stress_runner.sh Resolved
@antaljanosbenjamin antaljanosbenjamin self-assigned this Jul 2, 2026
Algunenano and others added 3 commits July 3, 2026 11:12
`0` means "unlimited" for all of these settings and disables the guard:
`parseQuery` only calls `checkDepth` when `max_parser_depth` is non-zero,
`IParser` only enforces the backtrack budget when `max_parser_backtracks` is
non-zero, and `executeQuery` skips the `max_ast_depth` / `max_ast_elements`
checks when the setting is `0`. A `<max>` constraint alone therefore still let
the fuzzer emit `SET max_parser_depth = 0` (etc.) to remove the safeguard.

Add `<min>1</min>` alongside each `<max>` so the valid range is [1, default].

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ings' into cap-fuzzer-stress-recursion-settings
Comment thread ci/jobs/scripts/fuzzer/run-fuzzer.sh Resolved
# tags and runs the query fuzzer over every query, so deeply nested expressions (e.g. test
# 04412's formatQuery of a 20000-deep array literal) would otherwise build huge queries that
# hang the server under sanitizers and trip the hung check.
cp -av --dereference /repo/ci/jobs/scripts/fuzzer/limit-recursion-settings.xml /etc/clickhouse-server/users.d/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clickhouse-test --stress-tests still runs the shell tests, and those wrappers append their own client flags after CLICKHOUSE_CLIENT_OPT (tests/queries/shell_config.sh:36-38). That means the new server-side profile here does not actually neutralize the stress case called out in the comment: 04411_deep_nested_field_to_type.sh:22 and 04412_deep_nested_literal_format.sh:19 both invoke $CLICKHOUSE_CLIENT --max_parser_depth=100000000, so the client-side parser still sees the uncapped depth and can spend minutes building the same 20k/30k-deep AST before the query ever reaches the constrained server session. In other words, copying limit-recursion-settings.xml into users.d fixes the server half, but the stress job can still hang in the shell-test client path. This needs a client-side enforcement that shell tests cannot override, or those deep-recursion shell tests need to be excluded from --stress-tests.

@Algunenano
Algunenano enabled auto-merge July 6, 2026 13:16
@Algunenano
Algunenano added this pull request to the merge queue Jul 6, 2026
Merged via the queue into ClickHouse:master with commit 37e41da Jul 6, 2026
174 checks passed
@Algunenano
Algunenano deleted the cap-fuzzer-stress-recursion-settings branch July 6, 2026 15:30
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 6, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…s-recursion-settings

Cap recursion-controlling parser/AST settings in fuzzer and stress test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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