Repository navigation
Let the hung check report what it saw instead of retrying past its deadline - #120303
Conversation
…adline The stacktrace dump never set max_http_retries, so it inherited the default 5. With its 120s socket timeout and the loop's min(i + 1, 3) sleeps its worst case is 5 * 120 + (1 + 2 + 3 + 3) = 609s, while the caller in stress.py waits 600s and then SIGKILLs the whole process group. The parent therefore killed the child in the middle of attempt five, so the except branch that prints "Failed to get processlist with stacktraces" never ran, and neither did the code that writes the "Hung check failed, possible deadlock found" row with a tail of the log. The job reported a bare "Test script failed" and hung_check.log held only progress dots. max_http_retries exists so each caller can pick its own policy: c1c278a introduced it for that, replacing a global constant. This caller runs under a deadline it can exceed, so it takes one attempt and fails at 120s with the rest of the budget left to report with. When the dump cannot be obtained, collect the C-level stacks as well. That is the dump which does not need the server to answer SQL, which is precisely the state this branch reports, and every other hung-or-dead-server path in the runner already takes it. It also covers the one cost of the retry change, since a transient HTTP error is now reported rather than retried. Both branches of get_processlist_with_stacktraces for clustered configurations get the same policy, so the SharedCatalog and replicated-database legs are not left behind. The stateless and fast-test callers of the collector are fixed too, since the change is in the collector rather than in a per-caller budget. Measured against a blackhole server: 609.3s over five attempts with gaps of 121.1/122.0/123.1/123.1s, matching the gaps in the server log of the reported run, and 120.0s over one attempt with this change. End to end under a parent mirroring stress.py, with system.stack_trace wedged: before, the parent's wait expired at 600s and the log held nothing but 40246 dots; after, the child exits 1 at 214s and the log carries the failure line and the stacktrace collection. Co-Authored-By: Claude Opus 5 <[email protected]>
The failure arm took only the C-level stacks. What the arm establishes is that the expensive aggregate over system.processes JOIN system.stack_trace did not return over HTTP; it does not establish that the server cannot answer SQL. The only firing of this arm in 60 days of CI (PR 112157, Stress test (arm_tsan), 2026-07-28) was a server-side Code: 159 TIMEOUT_EXCEEDED, elapsed 96139 ms against a 60000 ms max_execution_time, so the server was answering and enforcing its limits and only the JOIN plus symbolization could not finish. That is exactly where the plain system.stack_trace read still works: it goes over native TCP, bounded at 30s, and it is also the only dump that maps a stuck thread to its query_id. The C stacks need no answer from the server at all. Take both, SQL first, which matches the six other hung-or-dead-server dump sites in this file; all three job scripts already collect the pair. Both calls are bounded and neither propagates, so the arm still reaches exit_code.value = 1. With system.stack_trace wedged, the reporting path now ends at 247.8s of the parent's 600s budget, 33.6s more than with the C dump alone, and carries the failure line, the SQL collector's "Collected no stacks from system.stack_trace" and the C collection. Add a stateless test for the retry budget. It loads tests/clickhouse-test as a module, records what get_processlist_with_stacktraces passes to the executor, and pins one attempt and the 120s socket timeout on all three of its branches. The cluster name is printed alongside them so that three lines produced by one branch cannot pass, and the timeout is pinned as well as the attempt count because the bound this establishes is their product: raising the socket timeout later has to redden the test too. It reports the budget that takes effect rather than the argument that sets it, so a branch which stops passing the argument and inherits clickhouse_execute's default is caught by value. Against the runner on master all three lines report five attempts, so the test fails there and passes here. Co-Authored-By: Claude Opus 5 <[email protected]>
The report goes into a block-buffered pipe. stress.py runs the hung check with `stdout=tee.stdin`, the stress image does not set PYTHONUNBUFFERED and the job's own `docker run` does not pass it, and the runner is reached through its shebang, so CPython buffers 8 KiB of its output. After the failure line is printed the arm spends up to ~150 s in bounded collection (30 s reading system.stack_trace, 120 s in lldb) while the caller kills the process group on its own 600 s deadline. A kill inside that window discards the buffer, and the log again holds nothing but progress dots, which is the symptom this change exists to remove. Flushing before the dumps makes the report durable under that kill instead of relying on CPython's flush at process exit, which covers only a normal exit. Measured with two copies of the runner differing in exactly this line, both killed at 230 s while collecting: without it the log carries no `Hung check failed` line at all, with it the line reached the log 19.5 s before the kill. The normal path is unchanged, exit 1 after 254.6 s with the failure line and both collections present.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex), plus my own cold read of the
Noted, not blocking: the collectors' own progress lines stay buffered after the flush, so a kill Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20260915-231300 |
|
Workflow [PR], commit [8eaf13a] Summary: ✅ AI ReviewSummaryThis PR makes the end-of-run hung check fail fast on the expensive Final Verdict✅ No findings. LLVM Coverage ReportMeasured on commit 8eaf13a.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +131 lines in 46 files (-121 lines lost coverage) · Details |
| # and the attempt count on all three of its branches. The cluster name is | ||
| # printed as well so that three lines produced by one branch cannot pass. | ||
|
|
||
| CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
There was a problem hiding this comment.
Removed in 8eaf13a (the test and its reference). It pinned the effective 120 s timeout and the single attempt on the three collector branches, so that invariant is now unpinned in CI; the change itself is unchanged and the PR is down to the 15 lines in tests/clickhouse-test.
The test module-loaded tests/clickhouse-test and pinned the effective socket timeout and attempt count on the three get_processlist_with_stacktraces branches. Removed at the reviewer's request on ClickHouse#120303; the retry budget and the flush stay verified out of tree by the runs recorded in the PR description.
Related: #115706
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Requested by @ alexey-milovidov on #115706: the harness half of that incident, kept out of #120216 which fixes the server-side deadlock. The defect is in the harness here, so that is where the fix goes: a hung check that cannot say what it saw.
Stress test (arm_release)reportedTest script failedwithhung_check.logholding only progress dots. The dump querysystem.processes JOIN system.stack_tracenever setmax_http_retries, so it inherited the default 5; with its 120 s socket timeout and the loop'smin(i + 1, 3)sleeps its worst case is5 * 120 + 9= 609 s, against the 600 shung_check.waitinstress.py, which thenSIGKILLs the process group. The parent killed the child during attempt five, so theexceptbranch that prints what the check saw never ran, and neither did the code that writes theHung check failed, possible deadlock foundrow with a tail of the log.max_http_retriesis a per-caller knob, added by c1c278a for this purpose. This caller runs under a deadline it can exceed, so it takes one attempt and fails at 120 s with the rest of the budget left to report with. All three branches of the collector get it, so the SharedCatalog and replicated-database legs are covered, and the stateless and fast-test callers are fixed too, since the change is in the collector rather than in a per-caller budget.When the dump fails, the stacks are collected anyway: the plain
system.stack_traceread over TCP, which still works when only the expensive aggregate could not finish, and the C-level stacks, which need no answer from the server at all. Every other hung-or-dead-server path in the runner already takes that pair. That also absorbs this change's one cost, a transient HTTP error now being reported rather than retried.Measured, including the failure end to end
Against a socket that accepts and never answers, the collector takes 609.3 s over 5 attempts with gaps of 121.1 / 122.0 / 123.1 / 123.1 s, and 120.0 s over one attempt with this change. Those gaps match the server log of the reported run (dump attempted at 09:39:27 / 09:41:28 / 09:43:30 / 09:45:33 / 09:47:36), so the 609-vs-600 arithmetic is confirmed independently of it. Forcing the new constant back to 5 returns the collector to 609.4 s, and each of the three branches is measured separately: 1 attempt with the change, 5 without.
End to end, with
system.stack_tracewedged by the defect #120216 fixes and the hung check run under a parent mirroringstress.py(own session,tee,wait(timeout=600),killpgon expiry):hung_check.logTimeoutExpiredat 600.0 s, group killedrc = 1is what firesstress.py'sres != 0 and have_long_running_queriesgate, so the row is written with a tail that now holds the failure line. That line is also flushed before the collectors run, since the child's stdout is a block-buffered pipe: had the deadline expired during them, an unflushed report would have died with theSIGKILL.A batch of stateless tests with
--hung-checkstill exits 0, printsNo queries hung., reaches the log-message statistics report, and does not collect stacks: the reporting arm and the success arm are exclusive.There is no in-repo test: the runner assertion that pinned one attempt and the 120 s timeout on the three collector branches was removed on review. Coverage is out of tree, in the runs above, since the hung-check block is inline in
main().Workflow [PR]
Sync PR [sync-upstream/pr/120303]
Version info
26.10.1.168(included in26.10and later)