Repository navigation
Make isProbablePrime cancellable and cap rounds to 256 - #104633
Closed
alexey-milovidov wants to merge 1 commit into
Closed
alexey-milovidov wants to merge 1 commit into
alexey-milovidov wants to merge 1 commit into
Conversation
`isProbablePrime` on `UInt128`/`UInt256` delegated to `boost::multiprecision::miller_rabin_test`, which has no cancellation hook. Under heavy sanitizer + ThreadFuzzer instrumentation, a single round can stretch into minutes; combined with the server-side AST fuzzer mutating the `rounds` literal, the function hangs the stress test's `hung_check` for the full 30-minute window. This commit: - Adapts Boost's Miller-Rabin loop locally and calls `QueryStatus::checkTimeLimit` between rounds, so `KILL QUERY` and `max_execution_time` both interrupt the function. - Rejects `rounds > 256` with `BAD_ARGUMENTS`. `4^-256 < 10^-150` already, so larger values add no meaningful confidence and only widen the worst-case runtime under the AST fuzzer. See CI report on the AST-fuzzer-re-enablement PR: #101354 https://s3.amazonaws.com/clickhouse-test-reports/PRs/101354/f0038d26f27dc2d179136ae371e632746bab3c30/stress_test_arm_tsan/hung_check.log Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [11694fc] Summary: ✅ AI ReviewSummaryThis PR makes ClickHouse Rules
Final Verdict
|
This was referenced May 11, 2026
Contributor
LLVM Coverage Report
Changed lines: 87.65% (71/81) · Uncovered code |
alexey-milovidov
added a commit
that referenced
this pull request
May 12, 2026
A single `Primality::isProbablePrime` call on a wide `UInt128`/`UInt256` input runs many Miller-Rabin rounds; under the ASan+UBSan instrumentation of `function_prop_fuzzer`, this can take longer than the test's 30 second stop deadline, and the worker is then reported as stuck. The cancellation hook added in #104633 cannot help here: the stress test has no `QueryStatus`, so `check_cancelled` is a no-op. Add a hard constraint that caps the first argument at 1000, forcing the function through its fast bitmap / UInt64 path on every iteration. The function is still exercised on all supported input types - just on small values. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104639&sha=708387ba14ed6c25931b4d202c9198fc9d6cb223&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%2C%20function_prop_fuzzer%29 PR: #104639 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
grantholly-clickhouse
self-requested a review
May 12, 2026 18:30
grantholly-clickhouse
approved these changes
May 12, 2026
grantholly-clickhouse
left a comment
Contributor
There was a problem hiding this comment.
This should help CI run times.
Member
Author
|
Merged in #104639 |
Merged
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
isProbablePrimeonUInt128/UInt256delegated toboost::multiprecision::miller_rabin_test, which has no cancellation hook. Under heavy sanitizer + ThreadFuzzer instrumentation, a single round can stretch into minutes; combined with the server-side AST fuzzer mutating theroundsliteral, the function hangs the stress test'shung_checkfor the full 30-minute window.This PR:
Primality::detail::millerRabinTestBigand callsQueryStatus::checkTimeLimitbetween rounds, so bothKILL QUERYandmax_execution_timeinterrupt the function.rounds > 256withBAD_ARGUMENTS.4^-256 < 10^-150already, so larger values add no meaningful confidence and only widen the worst-case runtime under the AST fuzzer.The hang was discovered by the AST-fuzzer-re-enablement PR #101354: every stress test variant hits a
hung_checkon the same root cause —isProbablePrimeisis_cancelled=1but stuck inboost::multiprecision::miller_rabin_test→eval_powm. Example: https://s3.amazonaws.com/clickhouse-test-reports/PRs/101354/f0038d26f27dc2d179136ae371e632746bab3c30/stress_test_arm_tsan/hung_check.logChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Function
isProbablePrimenow respectsKILL QUERYandmax_execution_timemid-computation, and rejects unreasonably largeroundsarguments (limit: 256) withBAD_ARGUMENTS.Documentation entry for user-facing changes