Repository navigation
Scale the lldb stacktrace budget by build flavor, keep timed-out dumps - #114565
alexey-milovidov merged 14 commits into
Conversation
get_stacktraces_from_lldb ran `lldb --batch -p <pid> -o 'thread backtrace all'` under a hard 30s timeout, justified by a comment asserting the backtrace "should finish in seconds even on a debug build with many threads; anything beyond that means lldb itself is wedged". That premise does not hold. Measured against a live 174-thread debug server inside clickhouse/stress-test (the CI image, 8 CPUs, no debuginfod), a healthy attach takes 44-118s, exits 0, and returns a complete symbolized dump: the cost is the debug binary's unwind and symbol work, not a wedge. The same measurement on the fleet host reported 474s, but the 6-thread watchdog took 467s there too, which exposed it as network symbol fetching (DEBUGINFOD_URLS set); with external lookup off the same attach took 21s. Any budget derived from the host figure would be about 10x too large, so every number here comes from the CI image. A second, independent defect turned each timeout into total data loss. shell_get_output honoured keep_output_on_error only inside `except subprocess.CalledProcessError`, and subprocess.TimeoutExpired is not a subclass of it, so a timeout reached the generic handler and returned "". print_c_stacktraces then saw len(bt) < 1000 and printed "Got suspiciously small stacktraces from <pid>:" with nothing after it. In 90 days CIDB carries 181 `suspiciously small stacktraces` rows over 118 PRs and 80 `timed out after 30 seconds` rows over 59 PRs, 78 rows carrying both, so the reports of a wedged server routinely have no C stacks at all. The per-PID budget now depends on the build flavor, reusing the slow_build predicate (debug, any sanitizer, coverage) that MergeTreeSettingsRandomizer.get_random_settings already uses for the same reason: 120s on a slow build, 30s unchanged on release. It is not sanitizer-specific; Stress test (arm_debug) accounts for 51 of those 80 timeout rows, against 8 for all tsan/msan checks combined. The flavor is derived from args.build_flags and passed explicitly rather than read from the module-level RELEASE_NON_SANITIZED / SANITIZED globals, because clickhouse-test selects the "spawn" start method when CHECK_NAME contains "aarch" and a spawned worker re-imports the module with those globals back at False while args is transferred intact. A globals-based budget would therefore apply the release value on exactly the platform this fixes, while passing locally under fork. args.build_flags is absent on the startup-failure path, which calls print_c_stacktraces before collect_build_flags runs, so a missing flag set keeps the 30s budget instead of guessing or paying for a binary probe on an abort path. The pid loop can span up to 20 server processes, so a per-PID budget alone does not bound it. An aggregate ceiling now does, and it reports how many pids were skipped rather than truncating silently. The two call-site groups get different pairs. The per-test timeout handler runs from a fired one-shot signal.alarm, which cannot bound work inside its own handler, and what remains of the job's outer timeout has to cover print_sql_stacktraces and stop_tests as well: with the default --timeout 600 the alarm is int(600*1.1)+60 = 720s inside a 900s outer margin, and print_sql_stacktraces can cost 40s, leaving about 140s. That site therefore keeps today's 30s per PID with a new 60s aggregate ceiling, so it can only get safer. The abort paths (server died, hung check, startup failure) have no alarm pending and are additionally bounded outside the harness by the stress runner's own 600s wait, so they take the flavor budget with a 120s ceiling. No change to ci/jobs/functional_tests.py. On timeout the collected output is now kept. TimeoutExpired.output is bytes even when subprocess.run is given text=True, so it is decoded with the same errors="replace" policy as the call; returning it raw would violate shell_get_output's -> str contract, render the b'...' form with escaped newlines, and inflate len(bt) enough for an unreadable blob to pass the size guard. A truncation marker is appended and print_c_stacktraces no longer announces such a dump as the full backtrace. Killing a live attach at 10s and 20s leaves 48.7KB and 175 thread headers of usable real-server backtrace, all of which master discards. The len(bt) >= 1000 guard is unchanged: it still rejects the 93-byte "attach failed: No such process" output, and a rescued dump passes it on merit. Seven tests in ci/tests/test_print_stacktraces.py cover the budget per flavor, the post-spawn globals state, the missing-flags fallback, the aggregate deadline and its skip report, the tight pair at the timeout handler, the rescued dump with a matched control on the CalledProcessError path, and the partial-versus-full label. Each of the seven changes, reverted individually, reddens at least one of them. End to end against a live debug server: before, 30.8s and a 0-byte dump reported as suspiciously small; after, 63.6s and 834KB with 348 thread headers and 448 DB:: frames. The 30s cap was introduced in d45aa25 ("cap gdb stacktrace dump at 30s"); this corrects its premise rather than its intent, since a wedged debugger is still bounded.
Each block now states only the local invariant, within three lines: what the budget bounds, why the timeout branch is separate, why the flavor comes from args rather than the globals, and that the skipped pids are named. The measurements, the CIDB counts and the derivation of the numbers live in the previous commit message, where a reader who wants them can find them without carrying them past every future read of these lines.
… budget The aggregate ceiling promises to bound the whole pid loop, so it has to be read from a clock that only moves forward. time.time() is settable: a backward step inflates what is left and lets the loop run past the ceiling across up to 20 processes, a forward step skips processes that still had budget. The file already names this defect class where args.stop_time is computed. The second half is test-only. No test failed if print_c_stacktraces stopped honouring an explicitly passed per_pid_timeout: three of the new arms pass None, one reads the call site's source text, and the aggregate arm's own 2s ceiling clamps both candidate values to the same observable number. So the per-test timeout handler could silently take the 120s flavor budget where 30s was deliberately budgeted, since that handler runs inside its own fired alarm and only the job's outer timeout is left to bound it. The new arm passes a total_timeout larger than the per-PID value so the clamp cannot mask it.
Internal second-model review (click to expand)Two review rounds by a reviewer that does not author, each preceded by an Round 1: agreed and fixed❌ The aggregate lldb ceiling was built on a settable clock. ❌ No test pinned an explicitly passed per-PID budget. Dropping the Round 1: disagreed, with evidence
Noted, not blocking💡 The remaining budget is only tested for 💡 Truncation is detected by substring match, so a dump that itself contained the Session id: cron:clickhouse-review-self-slot-58:20260813-004300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20260812-181300 |
|
Workflow [PR], commit [ff43a26] Summary: ✅ AI ReviewSummaryThis PR makes Missing context / blind spots
Findings
Final VerdictChanges requested. LLVM Coverage Report |
|
cc @leshikus, could you review this? The lldb attach in clickhouse-test ran under a hard 30s timeout, but a healthy attach to a debug server measures 44 to 118s in the CI stress image, and a timed-out dump was then discarded entirely because keep_output_on_error did not cover TimeoutExpired, so the report kept no C stacks at all. |
The startup-failure caller in main() runs print_c_stacktraces before collect_build_flags assigns args.build_flags, so the flavor lookup had no flags and kept the 30s release budget on exactly the startup-hung case this change exists to improve. CIDB confirms the path is live rather than theoretical: of the 7 rows in 90 days carrying both "timed out after 30 seconds" and "Cannot execute 'SELECT 1' query", three show the startup message immediately followed by "Collecting C stacktraces", on Stress test (amd_debug) and (arm_debug) -- i.e. a debug server whose only preserved dump was cut off at 30s. Read the flavor from the binary via clickhouse local instead, the same server-independent route is_asan_build already takes when the flags are missing, querying the same three signals collect_build_flags derives (BUILD_TYPE=Debug, WITH_COVERAGE, -fsanitize=). An unreadable or unparseable result keeps the tighter budget, so an already-failing run cannot be made worse by the probe. Measured on real binaries: debug snapshot -> 120s, official 26.7 release -> 30s, unreadable path -> 30s without raising. Probe cost 0.16-0.17s.
The positive arm replaced is_slow_build_binary with a lambda, so the real
result parsing had no test: making it return False unconditionally left
every arm green while every debug startup failure kept the 30s budget.
Drive the real helper from what the query returns instead ("1"/"2" slow,
"0"/""/"x" not), and assert the query text names each signal
collect_build_flags derives, so the two cannot drift apart on what "slow"
means. Both mutations now redden: an unconditional False, and >0 becoming
>1.
…warding Two defects in the binary fallback added in the previous commit. The probe treated any -fsanitize= as slow, while collect_build_flags maps only thread, address, undefined and memory. CFI adds -fsanitize=cfi-vcall,cfi-derived-cast on top of RelWithDebInfo (CMakeLists.txt:527-529) and has its own stress job (ci/defs/job_configs.py:420), so an amd_cfi startup failure would have got 120s while the same binary, once started, got 30s. Name the same four sanitizers instead. Nothing proved get_stacktraces_from_lldb forwards the chosen budget to the lldb invocation: every budget arm stubs that collector out, so restoring a hardcoded timeout=30 inside it would have left all arms green with the slow-build budget silently disabled. Assert the forwarded timeout for both the explicit and default cases, and keep_output_on_error, without which a timed-out attach is unrecoverable. Mutations observed red: re-broadening to bare -fsanitize=, hardcoding timeout=30, and dropping keep_output_on_error.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
require_server=False only skips the precondition; the CI tests job still runs a live release server, so nothing stopped the probe from being turned into a live-server query or losing its bound, either of which puts the startup-failure path back on 30s or blocks the abort it diagnoses. Record the timeout alongside the command and assert the probe invokes args.binary with `local` and passes timeout=60. Both mutations redden: dropping the timeout, and swapping `local` for `client`.
print_c_stacktraces derived per_pid_timeout before the ASan guard and before the no-pids guard, and both return without reading it. On the startup-failure path (main -> check_server_started, which runs before collect_build_flags), the derivation falls back to reading the binary via `clickhouse local`, so an ASan job paid that 60s-bounded read and then paid is_asan_build's own 60s-bounded read of the same binary before printing the skip message: 120s of worst-case delay on an already-failing run, for no dump. Moving the derivation below both guards leaves the non-ASan path unchanged. Measured on the ASan startup-failure shape: 2 binary probes and 120s of worst-case bound before, 1 and 60s after; the non-ASan control still runs the flavor probe and still passes the 120s slow-build budget to lldb. The new arm drives both helpers from what their query returns rather than stubbing either, so the ordering cannot be hidden by a stub, and asserts the ASan half (one probe, no lldb call) independently of the non-ASan control.
The arm only supplied a live PID, so it pinned the ASan return ahead of the flavor derivation but not the no-process one. Moving the derivation between the two guards left all twelve tests green while an exited startup process would still pay the 60s binary read before the abort; with the no-PID arm that placement reddens. Test-only: the source already derives below both returns.
CI finish ledger - 1895127CI is fully finished at this head. 177 checks: 80 success, 97 skipped, 0 failures, 0 dropped No failures, so there is nothing to assign an owner to. Session id: cron:our-pr-ci-monitor:20260813-103000 |
Master deleted `ci/tests/test_print_stacktraces.py` along with most of `ci/tests/` in ClickHouse#114675, and `.claude/CLAUDE.md` now states the rule the deletion follows: a throwaway test for CI scripts need not be committed, because that suite is not run automatically. The 39 files restored after that PR did not include this one, so the deletion is the intended state and the merge takes master's side. The harness change is unaffected: the budget derivation, the binary-flavor fallback and the timed-out-dump retention are the same code that was reviewed, and master's own additions to `tests/clickhouse-test` are kept. Re-ran the deleted arms as a throwaway script against the merged tree and against the pre-merge head: 12 passed and the same 5 live-server arms skipped for want of a server in both, so the merge changes no behavior.
| for pid in all_pids: | ||
| # Costs a `clickhouse local` read of the binary when the flags are missing, | ||
| # and neither return above consumes it. | ||
| if per_pid_timeout is None: |
There was a problem hiding this comment.
print_c_stacktraces still does one discarded binary probe on the no-process startup-failure path. When check_server_started fails before collect_build_flags(args), args.build_flags is unset, so is_asan_build(args) shells out to clickhouse local here. If the server has already exited, we then hit the not all_pids return below and never use that ASan verdict for anything.
That leaves already-failing startup jobs paying an extra 60s-bounded probe before printing the only actionable message. Could we snapshot all_pids first and return on the empty case before probing the binary for ASan?
| def print_c_stacktraces( | ||
| args, | ||
| per_pid_timeout: Optional[float] = None, | ||
| total_timeout: float = LLDB_SLOW_BUILD_TIMEOUT, |
There was a problem hiding this comment.
total_timeout now defaults to the same LLDB_SLOW_BUILD_TIMEOUT that lldb_timeout_for_build(args) gives each slow-build PID. That means as soon as get_all_server_pids(args) returns more than one server, the first debug/sanitized process can consume the entire loop budget and every later replica is either truncated or skipped.
That breaks the multi-server case this helper is meant to cover. The built-in test_cluster_database_replicated cluster already has three server processes (tests/config/config.d/database_replicated.xml:89-106), and the replica holding the hang is not guaranteed to be the first PID. Could the abort-path ceiling scale with len(all_pids) (or at least budget one full slow-build attach per PID up to the outer job timeout) instead of reusing the per-PID constant as the whole-loop cap?
CI finish ledger — 7c0edc0Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Rule 3b, not 3d: Session id: cron:our-pr-ci-monitor:20260817-200000 |
master added a fifth default-budget call site (the LIVENESS_CHECK_FAILED abort) and reworded the docstring paragraph this branch also rewrote, so the two edits collided on one paragraph. Resolution keeps master's call-site enumeration, including "liveness check", and drops its "pause is on the order of seconds" sentence, which is the premise this branch replaces: a 172-thread debug server measured 44-118s in the CI stress image. The new site sits outside the one-shot alarm, so it correctly takes the default flavor budget; the timeout_handler site remains the only one passing an explicit (30, 60) because a fired alarm cannot bound its own handler. Two comments master added state a "30s per server process" bound for the same sweep. That constant is no longer the bound here (per-PID 30 or 120, plus a 120s aggregate ceiling), so both now name the budget instead of a number.
The source comments describing the sweep as bounded to 30s per server process were reworded in the merge commit. Two comments in the hung-check test file assert the same retired constant, so they say "the budget" now as well. Comment-only; the suite's outcome is unchanged (33 passed, the same 10 live-server arms failing as on master).
… budget fix Master extended this comment to cover the SQL dump stub as well, which matches the code below it (both `print_c_stacktraces` and `print_sql_stacktraces` are stubbed). Kept that framing and this branch's correction that the lldb sweep is bounded by the flavor-scaled budget rather than a flat 30 s per process. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Master removed the whole `ci/tests` directory in `5b3d66b1a66` ("Remove ci/tests
(attempt 2)", 51 files, no replacement location), so this branch's edits under
`ci/tests` arrive as modify/delete conflicts. Accepted the removal, and dropped
the files this branch adds there as well - keeping them would re-create a
directory master deliberately deleted.
The product change this pull request is about is unaffected; what is lost is its
CI-side unit coverage, which has nowhere to live upstream any more.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Related: #109455
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
clickhouse-testcollects C-side backtraces withlldb -o 'thread backtrace all'under a hard 30s timeout. On a debug server the attach needs longer, the timeout
fires, and the partial dump was discarded too, leaving no C stacks for the wedged
process. CIDB, 90 days: 181
suspiciously small stacktracesrows over 118 PRs, 80timed out after 30 secondsover 59 PRs, 78 carrying both. Two causes:build". Measured on a 174-thread debug server in the CI stress image, a healthy
attach takes 44-118s and returns a complete dump: the cost is symbolization.
shell_get_outputhonouredkeep_output_on_erroronly forCalledProcessError;TimeoutExpiredis not a subclass, so a timeout returned"", discarding what lldb wrote.The per-PID budget now scales with the build flavor, reusing the
slow_buildpredicate (debug, TSan/ASan/UBSan/MSan, coverage) that
MergeTreeSettingsRandomizeruses: 120s on a slow build, 30s unchanged on release (
Stress test (arm_debug)is 51of those 80 rows, so the driver is debug). The
flavor comes from
args.build_flags, not the module globals a spawned workerresets; the startup-failure caller runs before those flags exist, so there it is
read from the binary via
clickhouse local, likeis_asan_build. Aseparate aggregate ceiling bounds the pid loop and reports skipped pids. The
per-test timeout handler keeps 30s, running inside its own fired alarm. A
timed-out dump is now kept, decoded and marked truncated.
Validated against a live debug server with real lldb: before, 30.8s and a 0-byte
dump called suspiciously small; after, 63.6s and 834KB with 348 headers.
Forcing the budget below the attach cost keeps 48.7KB where master keeps 0. Reverting
each change reddened one of twelve arms, run as a throwaway script since master
no longer carries the
ci/testsfile that held them.Workflow [PR]
Sync PR [sync-upstream/pr/114565]
Version info
26.9.1.613(included in26.9and later)