Skip to content

Add cancellation check for system sync merges - #104944

Merged
Michicosun merged 5 commits into
masterfrom
limit_system_merges_queries
May 15, 2026
Merged

Michicosun merged 5 commits into
masterfrom
limit_system_merges_queries

Conversation

@Michicosun

@Michicosun Michicosun commented May 14, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

This patch fixes an infinite loop in these queries during stress tests. Now, the system sync merges query will loop up to receive_timeout seconds and also respect cancellation.

Version info

  • Merged into: 26.5.1.680

@clickhouse-gh

clickhouse-gh Bot commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [164778e]

Summary: ❌

job_name test_name status info comment
Unit tests (asan_ubsan, function_prop_fuzzer) FAIL
FunctionsStress FAIL cidb
libFuzzer tests FAIL
create_parser_fuzzer FAIL cidb

AI Review

Summary

This PR adds timeout and cancellation handling to SYSTEM SYNC MERGES by using max_execution_time, but one correctness issue remains in cancellation reason handling and evidence is still insufficient because the new behavior is not covered by focused regression tests.

Findings
  • ⚠️ Major: [src/Interpreters/InterpreterSystemQuery.cpp:2117] CurrentThread::get().isQueryCanceled only reports that the query was killed, not why. If CancellationChecker kills the query due to max_execution_time before the local deadline branch triggers, this code throws QUERY_WAS_CANCELLED instead of TIMEOUT_EXCEEDED, misclassifying timeout as user cancellation. Suggested fix: use process_list_element->checkTimeLimit or throwIfKilled instead of throwing directly from a boolean cancellation check.
Tests
  • ⚠️ Add focused stateless regression coverage for the new SYSTEM SYNC MERGES behavior: deterministic timeout path (max_execution_time -> TIMEOUT_EXCEEDED) and cancellation path (KILL QUERY -> QUERY_WAS_CANCELLED). Current tests do not prove either branch.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
  1. Preserve timeout vs cancellation reason in the syncMerges cancellation check.
  2. Add focused regression tests for the new timeout/cancellation behavior.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 14, 2026
poll_delay.setConfiguration(/*min_delay_=*/50, /*max_delay_=*/500, /*factor_up_=*/2.0, /*factor_lower_=*/1.0);

while (true)
const auto timeout = getContext()->getSettingsRef()[Setting::receive_timeout];

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.

This changes the contract of SYSTEM SYNC MERGES from unbounded wait to timeout-bounded wait, and also adds a cancellation exception path, but there is no focused regression test for either branch.

Please add a stateless test that proves at least one of these new outcomes deterministically (for example, low receive_timeout leading to TIMEOUT_EXCEEDED when scheduled parts cannot be covered, and/or cancellation leading to QUERY_WAS_CANCELLED). Without that, this bug-fix claim is not strongly evidenced and the behavior can regress silently.

@yariks5s yariks5s self-assigned this May 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 92.31% (12/13) · Uncovered code

Full report · Diff report

@Michicosun
Michicosun added this pull request to the merge queue May 15, 2026
Merged via the queue into master with commit 7a47203 May 15, 2026
164 of 167 checks passed
@Michicosun
Michicosun deleted the limit_system_merges_queries branch May 15, 2026 14:51
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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