Skip to content

Make waiting for mutations interruptible: Fix hung waitForMutation not respecting query cancellation - #96756

Merged
alexey-milovidov merged 6 commits into
masterfrom
fix-hung-waitForMutation
Feb 15, 2026
Merged

alexey-milovidov merged 6 commits into
masterfrom
fix-hung-waitForMutation

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • StorageMergeTree::waitForMutation used condition_variable::wait which blocks indefinitely without checking query cancellation
  • When a DELETE query is cancelled during stress tests, the wait never returns because the check lambda only looks at shutdown_called and mutation status
  • This caused hung check failures where DELETE FROM system.session_log queries from tests 02833_concurrent_sessions and 02834_remote_session_log hung for 1200+ seconds
  • The fix replaces the indefinite wait with a wait_for loop that periodically calls checkTimeLimit to detect query cancellation

CI reports:

Test plan

  • Build passes (RelWithDebInfo)
  • CI stress tests should no longer hang on DELETE FROM system.session_log

Changelog category (leave one):

  • Improvement

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

Synchronous waiting for mutations will respect query cancellation and time limits.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.2.1.690

`StorageMergeTree::waitForMutation` used `condition_variable::wait` which
blocks indefinitely without checking query cancellation. When a `DELETE`
query is cancelled during stress tests, the wait never returns because
the check lambda only looks at `shutdown_called` and mutation status,
not at the query's cancellation state.

This caused hung check failures in stress tests where `DELETE FROM
system.session_log` queries from tests 02833 and 02834 would hang
for 1200+ seconds after being cancelled.

The fix replaces the indefinite `wait` with a `wait_for` loop that
periodically calls `checkTimeLimit` on the process list element,
which throws an exception if the query was cancelled.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=eceab6911fb6b088b2a2cfa74afd0c139e700624&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=3c501a28a835615f110df7d21b07c7cc9a670422&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov alexey-milovidov changed the title Fix hung waitForMutation not respecting query cancellation Make waiting for mutations interruptible: Fix hung waitForMutation not respecting query cancellation Feb 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [908a8a8]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting between 'Function_array' and 'Literal_Array_[UInt64_1, Float64_3.402823669209385e38]' in the query: (STID: 1941-1bfa) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Feb 12, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

It's hard to write a targeted test for this improvement, but our stress tests provide some sporadic coverage.

@Algunenano Algunenano self-assigned this Feb 12, 2026

@Algunenano Algunenano left a comment

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.

Looks good to me. There are a few other cases (at least 65 just in public) of std::condition_variable::wait, but in a superficial review I don't see anything too suspicious

Since `waitForMutation` now respects `max_execution_time`, the ALTER TABLE
query with `mutations_sync = 2` may be cancelled with `TIMEOUT_EXCEEDED`
before the mutation itself fails with OOM. Both outcomes are valid — the test
verifies the server does not crash (issue #55279).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-ci labels Feb 12, 2026
alexey-milovidov and others added 4 commits February 13, 2026 20:28
Add `DROP TABLE IF EXISTS` before creating and after using the table,
so the test can be run multiple times in targeted/flaky CI modes
without failing with "Table already exists".

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@alexey-milovidov
alexey-milovidov merged commit 3d5e016 into master Feb 15, 2026
130 of 131 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-hung-waitForMutation branch February 15, 2026 00:35
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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