Repository navigation
Let the hung check read the processlist when the server is over its memory limit - #116545
Conversation
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings), plus my own cold
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260826-144800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260826-135100 |
|
cc @maxknv, could you review this? All three of the hung check's own queries aggregated, and |
|
Workflow [PR], commit [326e293] Summary: ✅ AI ReviewSummaryThis PR removes aggregation from the hung-check liveness probes and Final Verdict✅ No new inline findings. The current patch looks correct from the reviewed correctness and diagnostics standpoint. |
…emory limit `Stress test (amd_debug)` reported `Hung check failed, possible deadlock found` while the hung check had never managed to look at the server: all 180 of its liveness retries were refused with `Code: 241`. The leaf therefore carries no information about whether the check found a hang or failed to look for one. `stress.py` passes `--client-option max_untracked_memory=1Gi max_memory_usage_for_user=0 memory_profiler_step=1Gi` to the hung check for exactly this reason, but `--client-option` only becomes URL parameters inside `if args.cloud:` (`clickhouse-test:7242`), and every `clickhouse_execute_http` URL is built from that string, so no non-cloud run carries any of it. The native-client path is not cloud-gated, which is why `stress.py`'s own `make_query_command` queries kept working. The refusal itself comes from a check no untracked-memory setting can reach: `Aggregator::checkLimits` ends in `CurrentMemoryTracker::check()`, i.e. `allocImpl(0, /*enforce*/ true)`, and for a zero-sized allocation `MemoryTracker.cpp:309` makes `will_be` the current amount and compares it straight against the limit. Aggregation is therefore the exposure, and the check aggregated in all three of its own queries: the startup probe (`groupArray`), `get_processlist_size` (`count()`) and the stacktrace dump (`groupArray ... GROUP BY`). The `NOTE` above the `--client-option` list claiming "neither hung check, nor 00001_select_1 has GROUP BY" was never true, and its proposed remedy could not have worked, so it is deleted rather than corrected. Changes: * The startup probe uses scalar subqueries instead of `groupArray`. Removing the aggregation rather than lifting the limit here matters, because `check_server_started` runs for every `clickhouse-test` invocation and `max_memory_usage_for_user = 0` mutates the shared per-user tracker. * `get_processlist_size` projects `SELECT 1` and counts rows client-side, in all three branches. De-aggregating rather than exempting is what covers the two `clusterAllReplicas` branches completely: an override does reach the initiator's own local shard, but `ClusterProxy::executeQuery` sets `max_memory_usage_for_user = 0` for the shard query and then marks it unchanged, so it never reaches a remote replica. A literal `1` is projected rather than a column because the count is `splitlines()` and a projected value containing a newline would over-count. This continues the direction of 140f6da ("hung_check check with lighter queries"), which split the expensive dump into a cheap gate plus a heavy payload; `count()` was just the spelling of the day. * `get_processlist_with_stacktraces` folds several threads per query into one row, and rewriting that client-side would change the text `stress.py` embeds in the CI report, so it keeps its aggregation and gets an explicit per-user exemption instead, in all three branches. That is now the one place the shared tracker is touched, and it runs at most once per job, after the check already knows there is something to report. Only `max_memory_usage_for_user` is lifted: `max_untracked_memory` and `memory_profiler_step` make tracking coarse and are irrelevant to a zero-sized check. The exemption is per call site rather than in the shared `params` dict because `--hung-check` is on every functional lane and 11 stateless tests assert on that setting. It covers the initiator, which is the server that accumulates the workload (`clickhouse_proc.py` puts the other replicas on 19000 and 29000 while the runner talks to 9000); a replica that is itself over its cap cannot be exempted from the initiator and still fails there, on an ordinary allocation rather than on the zero-sized check. * `prepare_for_hung_check`'s `elapsed > 300` query goes through `make_query_command` like its sibling 16 lines above, so it carries the override too, and its bare `except:` now logs. Reporting "I could not tell" as "yes, there are long-running queries" with no log line at all is the defect; the conservative `return True` is kept. * The failure message no longer names a `SELECT 1` query that is never run. Nothing suppresses a verdict. Note that even with this change the hang in that particular run would still not have been named: `Context::setCurrentDatabase` deadlocks 139 lines before the process-list insertion in `executeQuery.cpp`, so those threads were never in `system.processes` at all. Only the thread dump had them, and the job already collects it. That server-side hang is a separate change. Related: ClickHouse#110626
241aa65 to
326e293
Compare
|
Correction (2026-09-26): point 2 below is wrong. GitHub concluded that job at 20:32:41Z with Follow-up measurement on the residual of this fix, from What the log shows. Two separate things go wrong, and only the first is what this PR was about.
Why I stopped instead of patching the probes. Raising the untracked limits cannot establish the The choices, as I see them. All of the real ones are yours, not mine:
For context, I have seen two other One thing I can do without a decision, if you want it: when the hung check dies during its own |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Related: #110626 (requested in this comment; I posted a correction to my first analysis of it)
Stress test (amd_debug)reportedHung check failed, possible deadlock found, but the hung check had not managed to look at the server: all 180 of its liveness retries were refused withCode: 241. Something really was hung, so the verdict was right by accident; the check itself never readsystem.processes.Root cause.
stress.pypasses--client-option max_memory_usage_for_user=0to the hung check for exactly this reason, but those settings only become URL parameters insideif args.cloud:(clickhouse-test:7202), and everyclickhouse_execute_httpURL is built from that string. MeanwhileAggregator::checkLimitscallsCurrentMemoryTracker::check(), a zero-sized allocation whosewill_beis the current amount, so no untracked-memory setting can affect it. Aggregation is therefore the exposure, and the check aggregated in all three of its own queries: the startup probe,get_processlist_size(count()) and the stacktrace dump. TheNOTEclaiming "neither hung check, nor00001_select_1has GROUP BY" was never true.The change drops the aggregation from the probe and from
get_processlist_size(including its twoclusterAllReplicasbranches), exempts the one query that must aggregate in all three of its branches, routesstress.py's last un-overridden query throughmake_query_command, stops a bareexcept:from reporting "I could not tell" as "yes" with no log line, and corrects a message that named aSELECT 1it never runs. Nothing suppresses a verdict.Reports: Stress test (amd_debug). Adjacent in intent: #115692.
I am sending the server-side hang,
Context::setCurrentDatabasedeadlocking against its ownContext::mutexthrough a database-name hint, as a separate PR. Note that even with this change that hang would not have been named: it happens before the process-list insertion (executeQuery.cpp:2651against:2791), so those threads were never insystem.processes.Validation (no test home exists for runner code;
ci/tests/is being removed)Fixture: a 953.67 MiB per-user cap and a query holding 2.0-2.8 GiB: the flap
setOrRaiseHardLimit(0)andProcessList.cpp:397produce in CI. Counters, not the exit code, are the oracle: both arms exit non-zero.Connection error, will retryAll connection tries failedServer is not respondingFailed to get processlist sizeFound hung queries in processlistThe base column matches the CI run's
hung_check.logexactly (180/1/2). The middle column is a de-aggregated probe only: the failure moves toget_processlist_size, so both changes are needed. With the fix the check names the holding query. Without memory pressure both arms exit 0 withNo queries hung., and 20 of 20 invocations plus--test-runs 50pass.Blast radius, from
query_log:max_memory_usage_for_user = 0on the stacktrace query (1 execution), the profile value on all 47157 other runner queries. Client-side counting is latency-neutral (p90 2 ms).The
clusterAllReplicasbranches carry the same exemption. Measured with the cap armed: unexempted they fail withchunk of 0.00 B, exempted they return the dump, on the initiator's own local shard; against a replica that is itself over its cap the exemption changes nothing, sinceClusterProxy/executeQuery.cppmarks the setting unchanged before forwarding and the test cluster has no<secret>. The initiator is the server the runner talks to, so it accumulates the workload.One bound:
setOrRaiseHardLimitrestores a positive limit, so a query inserted while the dump runs re-arms the cap and the dump can still fail (measured). A large positive value defeats that but is never lowered again, so 0 is kept; when the race fires the check prints the server's own error.Workflow [PR]
Sync PR [sync-upstream/pr/116545]