Repository navigation
Fix a missing --chime when a slow query ends with an error - #117179
Conversation
The chime compared its threshold against `ProgressIndication::elapsedSeconds`, which prefers the elapsed time reported by the server. That value only advances when a `Progress` packet arrives, and `TCPHandler::processOrdinaryQuery` sends a final `Progress` packet only on the success path - its exception path rethrows without one. So after a failed query the client's notion of the elapsed time is whatever the last periodic packet carried: normally one `interactive_delay` behind, but unbounded when the handler's loop iteration is delayed, because once the pipeline has recorded the exception the next `pull` throws before the loop reaches `sendProgress`. A query that visibly ran past the threshold could therefore finish with no chime. Gate the chime on the client's own clock instead. That is the wall-clock time the user actually waited for, which is what the chime is about, and it does not depend on the timing of progress packets. `Elapsed:`, `--time` and the throughput calculations keep using the server-reported time, so no other output changes. This is what made `04312_client_chime_on_slow_query_92718` flaky: case 11 exercises the error path over a pty with `--chime 1` against a ~1.5-second query, and on a loaded machine the last progress packet can predate the 1-second mark. Every recorded failure of the test over the last 30 days is case 11 and nothing else. Case 13 turns that into a deterministic check by raising `interactive_delay` so the server sends exactly one `Progress` packet, at ~0.9s, and none after it. Cases 4 and 11 also stopped identifying the expected failure by the `expected error` message, which the client's echo of the failed query text made vacuous, and now match on `FUNCTION_THROW_IF_VALUE_IS_NON_ZERO`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=9904bd2786b3927e436b043c555231828d3f069f&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%201%2F3%29 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [3d787b7] Summary: ✅
AI ReviewSummaryThis PR switches the Findings
|
| Metric | Baseline | Current | Δ |
|---|---|---|---|
| Lines | 88.60% | 88.60% | +0.00% |
| Functions | 92.10% | 92.10% | +0.00% |
| Branches | 80.90% | 80.90% | +0.00% |
Changed lines: Changed C/C++ lines covered: 8/8 (100.00%) · Uncovered code
| # clock this case reports `no BEL`, which is also what made case 11 flaky under CI load: there the | ||
| # same staleness comes from a delayed `TCPHandler` loop iteration rather than from a large | ||
| # `interactive_delay`. | ||
| /usr/bin/script -eqc "${CLICKHOUSE_CLIENT} --chime 1 -q \"SELECT throwIf(sleep(1.5) = 0, 'expected error') SETTINGS interactive_delay = 900000\"" /dev/null > "$tty13" 2>&1 |
There was a problem hiding this comment.
TCPHandler only emits that progress update after executor.pull(block, interactive_delay / 1000) times out, and PullingAsyncPipelineExecutor implements the timeout via ConcurrentBoundedQueue::tryPop(..., milliseconds) / std::condition_variable::wait_for. With --chime 1 and interactive_delay = 900000, the old code is only guaranteed to stay below the threshold if that first 900 ms wait wakes within ~100 ms of schedule. On a loaded runner it can legally slip past 1.0 s, at which point the lone Progress packet already carries elapsed_ns >= 1s and the pre-fix client rings, so this regression passes without the fix. Please widen the gap here so the last pre-error progress update is forced safely below the threshold.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units22 translation units recompiled, 122 s compile time in total, 22 of them have a recent master baseline. |
Related: #92718
Related: #104545
Description
--chimedecided whether a query ran long enough by comparing its threshold againstProgressIndication::elapsedSeconds, which prefers the elapsed time reported by the server over the client's own clock. The server-reported value only advances when aProgresspacket arrives, andTCPHandler::processOrdinaryQuerysends a finalProgresspacket only on the success path - the exception path rethrows without one. So after a failed query the client's notion of the elapsed time is whatever the last periodic packet happened to carry: normally oneinteractive_delaybehind, but unbounded when the handler's loop iteration is delayed, because once the pipeline has recorded the exception the nextpullthrows before the loop reachessendProgress. A query that visibly ran past the threshold could therefore finish with no chime.Measured against a local server (the reported time is
--time, the real one is/usr/bin/time):The chime is now gated on the client's own clock (
ProgressIndication::clientElapsedSeconds). That is the wall-clock time the user actually waited for, which is what the chime is about, and it does not depend on the timing of progress packets. The server-reported time is still whatElapsed:,--timeand the rows/bytes-per-second calculations use, so this does not change any other output; the residual staleness of those numbers after an error is pre-existing and left alone.This is what made
04312_client_chime_on_slow_query_92718flaky. Case 11 exercises the error path over a pty with--chime 1against a ~1.5-second query, a 0.5-second margin; on a loaded CI machine the last progress packet can predate the 1-second mark, and the case reportsno BEL. Every recorded failure of this test on master and in pull requests over the last 30 days is case 11 and nothing else.The failure reproduces on demand by making the server send exactly one progress packet, below the threshold, and none after it -
2 * 0.9sis past the moment the query throws:That is added as case 13, so the test now covers the contract that used to be flaky rather than relying on a timing margin. Cases 4 and 11 also stopped identifying the expected failure by the
expected errormessage: the client echoes the failed query text, which contains that message, so the check passed for any failure at all - they now match on theFUNCTION_THROW_IF_VALUE_IS_NON_ZEROerror code name.CI report for the failure this fixes: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=9904bd2786b3927e436b043c555231828d3f069f&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20parallel%2C%201%2F3%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
clickhouse-clientandclickhouse-localnot emitting the--chimealert for a long-running query that ends with an error. The threshold was checked against the query time last reported by the server, which is not refreshed when a query fails, so it could be arbitrarily behind the real duration of the query. It is now checked against the time the client actually waited.Workflow [PR]
Sync PR [sync-upstream/pr/117179]