Repository navigation
Conversation
The pending-state kill check in executeQueryImpl unconditionally threw QUERY_WAS_CANCELLED. When max_execution_time fires before execution starts (e.g. during planning), the query is cancelled with CancelReason::TIMEOUT, so the correct error is TIMEOUT_EXCEEDED, matching a timeout during execution. Consult QueryStatus::getCancelReason() and throw TIMEOUT_EXCEEDED when the reason is TIMEOUT, otherwise QUERY_WAS_CANCELLED (same as PullingPipelineExecutor). This is the race behind the flaky 01039_mergetree_exec_time failure under Stateless tests (amd_tsan, parallel). A new failpoint execute_query_sleep_before_pending_kill_check makes it deterministic; the regression test is 03471_pending_query_timeout_error_code. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-4:20260715-102300 |
|
cc @KochetovNicolai @vdimir for review: this fixes the error code ( |
|
Workflow [PR], commit [1f726d8] Summary: ❌
AI ReviewSummaryThis PR routes the pending-state cancellation check in Missing context / blind spots
Final Verdict✅ No blocking or major issues found in the current patch. |
Instead of open-coding only the TIMEOUT->TIMEOUT_EXCEEDED case and defaulting every other pending-state kill to QUERY_WAS_CANCELLED, route through QueryStatus::throwIfKilled (-> throwProperExceptionIfNeeded). This preserves the full cancellation mapping: TIMEOUT_EXCEEDED for a max_execution_time timeout, the concrete stored exception when the kill carried one (e.g. CancelReason::CANCELLED_BY_ERROR with FAILED_TO_SYNC_BACKUP_OR_RESTORE from BackupCoordinationStageSync), and QUERY_WAS_CANCELLED otherwise. Addresses the AI review on PR ClickHouse#110533. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Addressed in 5bf3a7c. Replaced the open-coded TIMEOUT special-case with `process_list_entry->getQueryStatus()->throwIfKilled()`, which funnels through `throwProperExceptionIfNeeded`. The pending-state path now matches the rest of QueryStatus: TIMEOUT_EXCEEDED for a max_execution_time timeout, the stored `cancellation_exception` when the kill carried one (e.g. `CANCELLED_BY_ERROR` + `FAILED_TO_SYNC_BACKUP_OR_RESTORE` from |
CI finish ledger — 5bf3a7cAll failures on this commit are the single ongoing infra runner outage; none are caused by this PR's diff. Every failure has an owner.
Session id: cron:our-pr-ci-monitor:20260715-153000 |
CI finish ledger — 5bf3a7cCI fully finished (Finish Workflow pass). The only red job is the fleet-wide host-OOM window; not PR-caused.
|
…g-timeout-exec-time # Conflicts: # src/Common/FailPoint.cpp
The pending-state kill now funnels through QueryStatus::throwIfKilled (this PR), so a user KILL of a pending query reports the standard cancellation message "Query was cancelled" (QUERY_WAS_CANCELLED, code 394) instead of the previous ad-hoc "is killed in pending state" text. Align the test assertion with the message used by the sibling KILL-query integration tests (test_mysql_kill_query, test_mongodb_kill_query). Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code |
CI finish ledger — 1f726d8Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Not PR-caused: this PR's diff is the executeQuery pending-state kill path (throwIfKilled); both failures are pre-existing chronic flakes on unrelated tests. Session id: cron:our-pr-ci-monitor:20260719-233000 |
|
@vdimir this PR's core fix is now superseded on master. #111208 (merged today) applies the same fix for the identical root cause: pending-state The only remaining delta here is generalizing the pending check to an unconditional I suggest closing this as superseded by #111208, unless you want the non-timeout |
| -- e.g. during planning). Such a query must report TIMEOUT_EXCEEDED, not QUERY_WAS_CANCELLED. | ||
| -- The failpoint stalls the main thread so the timeout deterministically fires in the pending state. | ||
|
|
||
| SYSTEM ENABLE FAILPOINT execute_query_sleep_before_pending_kill_check; |
There was a problem hiding this comment.
If we already have test_cancel_freeze, which changes with the patch, do we need to add a failpoint and a new test?
There was a problem hiding this comment.
No. On the current base 03471 is not load-bearing, and the failpoint exists only to make it deterministic.
Measured: substituting master's narrower form for this PR's unconditional throwIfKilled() and rebuilding (keeping the failpoint so the test can run at all), 03471 still passes.
| pending-state scenario | this PR | master (#111208) |
|---|---|---|
max_execution_time fires while pending |
Code 159 TIMEOUT_EXCEEDED | Code 159 TIMEOUT_EXCEEDED |
KILL QUERY of a pending query |
Code 394 Query was cancelled |
Code 394 Query 'X' is killed in pending state |
So test_cancel_freeze is the only assertion that moves, exactly as you say.
That is because the PR is superseded: 5843b0e (#111208, 2026-07-21) landed the identical timeout fix, which was this PR's original purpose. I raised that in #110533 (comment), which was easy to miss.
What remains of the diff is only the generalization to an unconditional throwIfKilled():
- rethrow a stored exception when the kill carried one (
CANCELLED_BY_ERROR). OnlyBackupCoordinationStageSync.cpp:760and:815pass one, and nothing here reaches that in the pending state, so this half is untested. - the plain-KILL message change, which is what forced the
test_cancel_freezeedit. Fix flaky 03309_json_with_progress_exception: timeout in pending state #111208 deliberately kept the distinct message, so this is a design fork, not a gap.
My recommendation is to close this as superseded. If you would rather keep the CANCELLED_BY_ERROR rethrow, I will respin it narrow: drop the failpoint and 03471, keep that branch only, and cover it directly instead of via the message change.
What's pros and cons of each in short? Can we close this PR? |
|
Yes, please close it. Option A, close as superseded by #111208:
Option B, keep the unconditional
If the |
Related: #109360
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the error code returned when a query is killed by
max_execution_timebefore it starts executing (for example while it is still being planned). Such a query now reportsTIMEOUT_EXCEEDEDinstead ofQUERY_WAS_CANCELLED, matching the behavior of a timeout that fires during execution.Description
The check for a query killed in the pending state (in
executeQueryImpl) unconditionally threwQUERY_WAS_CANCELLED, ignoring the cancel reason. When themax_execution_timetimeout fires while the query is still pending (before any pipeline executor is started, e.g. during planning),CancellationCheckercancels the query withCancelReason::TIMEOUT, but the pending-state check reportedQUERY_WAS_CANCELLED(394) instead ofTIMEOUT_EXCEEDED(159).This is the race behind the flaky
01039_mergetree_exec_timefailure underStateless tests (amd_tsan, parallel), where TSan's slowdown makes the timeout likely to fire before execution starts: the test expectsTIMEOUT_EXCEEDEDbut occasionally gotQUERY_WAS_CANCELLED. See https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109360&sha=f4d7ea385828706b6c33bcd9e056cce835612765&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20parallel%29 (surfaced on #109360, which is unrelated to this code).Fix: consult
QueryStatus::getCancelReason()in the pending-state check and throwTIMEOUT_EXCEEDEDwhen the reason isTIMEOUT, otherwiseQUERY_WAS_CANCELLED(same precedent asPullingPipelineExecutor, which already recovers the timeout reason when a timeout fires before execution starts).A new failpoint
execute_query_sleep_before_pending_kill_checkdeterministically reproduces the race by stalling the main thread so the timeout fires in the pending state; the regression test03471_pending_query_timeout_error_codeuses it. Verified: the test returnsQUERY_WAS_CANCELLED(394) without the fix andTIMEOUT_EXCEEDED(159) with it.