Repository navigation
Cherry pick #96450 to 25.3: Fix livelock in CancellationChecker caused by timeout overflow - #96527
Merged
Merged
Conversation
Two issues were causing CancellationChecker::workerFunction() to spin instead of waiting: 1. Overflow in wait_for: When a query was registered with an extremely large timeout (e.g., ~9.2e12 ms, close to INT64_MAX), the std::condition_variable::wait_for() would overflow when converting milliseconds to nanoseconds internally (multiplying by 1,000,000). This caused wait_for to return immediately instead of waiting. 2. Stale now_ms in predicate: The predicate lambda captured now_ms by value, but this timestamp was computed before the wait. On spurious wakeups, the predicate would compare the task's endtime against the stale timestamp, incorrectly returning false even when the task had actually expired. Combined with issue #1, this caused infinite spinning. Fix: - Cap timeout to 1 year maximum to prevent chrono overflow - Use fresh timestamp inside the predicate to correctly detect expiration
Verifies that queries with extremely large max_execution_time values (close to INT64_MAX) complete normally without causing livelock.
When a query has no timeout (max_execution_time <= 0), it is not registered with CancellationChecker. Previously, appendDoneTasks() was still called unconditionally in ProcessListEntry destructor, which would lock the mutex and search through the set for nothing. Now appendTask() returns a bool indicating whether registration occurred. This flag is stored in ProcessListEntry and used to skip the unnecessary appendDoneTasks() call and mutex lock.
…velock Fix livelock in CancellationChecker caused by timeout overflow
serxa
marked this pull request as draft
February 10, 2026 16:11
Contributor
There was a problem hiding this comment.
Pull request overview
Backport of a fix intended to prevent livelock/hangs in CancellationChecker when extremely large timeouts overflow chrono conversions.
Changes:
- Add a stateless test covering extremely large
max_execution_timevalues. - Cap tracked query timeout to 1 year (ms) to avoid
wait_foroverflow. - Adjust
workerFunction()wait predicate to use a fresh timestamp on re-evaluation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/queries/0_stateless/03903_cancellation_checker_large_timeout.sql | Adds coverage to ensure huge timeouts don’t hang the server. |
| tests/queries/0_stateless/03903_cancellation_checker_large_timeout.reference | Expected output for the new stateless test. |
| src/Interpreters/CancellationChecker.h | Minor comment punctuation change. |
| src/Interpreters/CancellationChecker.cpp | Implements timeout capping and updates waiting logic to avoid overflow/spin. |
Co-authored-by: Copilot <[email protected]>
serxa
marked this pull request as ready for review
February 10, 2026 16:29
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.
Original pull-request #96450
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job