Repository navigation
Collect the full diagnostics when a stateless job fails during setup - #117294
alexey-milovidov merged 1 commit into
Conversation
`functional_tests.py` assigns `test_result` only inside the test stage, so a setup failure leaves it `None`. `test_run_failed` is derived from it alone, reads `False`, and `prepare_logs` runs with `all=False`: core dumps, system-table dumps, the object-storage service log, dmesg and the Keeper logs are discarded for exactly the runs that have no test results to explain themselves with. Found while investigating a `Stateless tests (amd_tsan, flaky check)` failure on 2def28a, where `prepare_stateful_data` hit its per-statement bound on `INSERT INTO test.hits_s3 SELECT * FROM test.hits`. That job's `result.json` has three children (`Install ClickHouse`, `Start ClickHouse Server`, `Collect logs`, `Failures: 1/3`), and its `job.log` records `send TRAP signal to generate core file` and `Collect logs` in the same second: the harness asked the kernel for a core with the core, system-table, object-storage-log, dmesg and coordination branches all switched off. Whether a core survived the ten-second wait that follows the `SIGTRAP` cannot be told from what was uploaded, which is itself the problem. Of the 403s an earlier investigation saw, `dmesg.log` is the one fully explained by this defect. In CIDB over 30 days that three-child shape covers 58 job-level rows of `Stateless tests (...)` lanes, across 28 commits and 19 of those lanes, at least 45 of them in lanes that do collect logs. Four changes: - Capture an external all-thread backtrace when a prep statement hits its bound. Both in-process routes are dead for the case that needs them: the `SIGTRAP` in `stop_server` produced no log output at all, and `SYSTEM FLUSH LOGS` returned `Code: 209 SOCKET_TIMEOUT`, so `system.stack_trace` is unreachable. Meanwhile the wedged server stayed alive and unexamined for ten minutes between the prep returning and teardown starting. `STACK_CAPTURE_TIMEOUT_S` is 300s, derived from measurement rather than guessed: on the failing job's own TSan binary (build id 66b21ff2c033) a capture took 16.7s idle over 203 threads, 20.5s and 20.6s loaded over 347 threads, and 13.5s for the literal command emitted here over 381 threads, resolving 1874 `DB::` frames of which 1280 carried `at ./src/...` file and line. `tests/docker_scripts/stress_tests.lib` allows 1800s for the identical command, so 300s is the conservative end. Two consecutive attaches during an insert left the server serving and the insert completed, so the capture does not disturb what it inspects. - Skip that capture on ASan builds, where attaching a debugger disables LeakSanitizer. `tests/clickhouse-test` already applies this policy in `print_c_stacktraces` and its message is reused verbatim so the same wording appears in `job.log`. The test matches `"ubsan"` as well as `"asan"` so that a build name carrying `ubsan` without `asan` (which this repository's defs do not produce, though `functional_tests.py:55` and `src/Core/tests/gtest_protocol_packet_to_string.cpp:23` both refer to private `amd_ubsan` and `arm_ubsan` lanes) is skipped rather than captured. No build type in the tree changes behaviour, since both in-tree `ubsan` names already contain `asan`. `arm_fuzzers` is also built with `SANITIZE=address` and matches neither, but it is consumed only by `libFuzzer tests`, which never runs `functional_tests.py`; a branch for it would be dead code. - Require `timeout`'s own TERM diagnostic before treating exit 124 as an expiry. 124 is also the ClickHouse error code `INCORRECT_ELEMENT_OF_SET`, which the client returns from `main`, so the code alone does not distinguish a bound firing from a server exception. This mirrors the existing treatment of 137. The needle deliberately contains no quotes: the real diagnostic quotes the command name with U+2018/U+2019 under a UTF-8 locale, so a needle written with ASCII quotes would silently never match. The predicate reads the whole prep log rather than the fifteen-line tail the error message uses. `Shell.run` streams stdout and stderr into one file, so the diagnostic and the ERR trap are the last lines written and a tail normally holds them, as it did here; reading the whole log removes the dependence on that ordering. The tail itself is sliced with `io.StringIO(text).readlines()`, which is exactly what the previous `f.readlines()` produced, rather than `str.splitlines`, which also breaks on `\x0b`, `\x0c`, `\x1c`-`\x1e`, U+0085 and U+2028 and would have altered the recorded message. - Produce `dmesg.log` in the full-collection path. Its only other producer is the OOM check, which needs test results to grade, so a setup failure never wrote the file that the collection list then looked for. Where that check has already run, its graded file is left untouched and the current buffer is written beside it as `dmesg.at-collect.log`, because `start` clears the ring buffer for each server generation: declining to capture would upload an earlier generation's buffer, and overwriting would leave the graded `OOM in dmesg` row disagreeing with the uploaded bytes. A setup failure that never reached `start` gets an uncleared buffer, so its dump can include lines from earlier on the host; nothing grades it, because the fatal scan needs test results. A `dmesg` that fails leaves an empty file behind, because the shell creates the redirect target first, so that file is removed and a warning printed rather than uploaded as an empty dump that reads as "no OOM". The capture is written under `log_dir` as `stateful-prep-stacks-<pid>.log`, which is uploaded on every collection and matches none of the `clickhouse-server*.log`, `clickhouse-server*.err.log` or `stderr*.log` globs that `check_fatal_messages_in_logs` greps for `<Fatal>` and sanitizer text, so a backtrace cannot become a false blocker. `gdb` exits 0 even when an attach is refused, so its stderr is redirected into the same file and the artifact explains its own emptiness; `Shell.check` cannot raise, so a missing or unattachable `gdb` leaves the job's outcome unchanged. This does not fix the hang underneath the reported failure. That server logged normally for 35.4s of the insert, then emitted nothing for 62.0 minutes from any of the 186 threads that had ever logged, never raised `max_execution_time`, answered no new query, and ignored SIGTERM for 300s. Naming the mechanism needs a thread stack, and none of the seven occurrences in 90 days produced one, or a core, or a `fatal.log`. An earlier revision of this work instead bracketed the fixture load with `SYSTEM STOP/START THREAD FUZZER`; that was withdrawn after measurement, because the fuzzer accounts for 1.76x against a failure of more than 23.7x, its pthread wrappers are compiled out under TSan, and five arms including one at five times the CI fuzzer strength all completed with continuous logging. Perturbing the timing of the thing being diagnosed could also have made the only occurrences available disappear. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110321&sha=2def28ac1fbdc8166d4e6c37c00ab830b4248148&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 Related: ClickHouse#110321 Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review of this change: my own cold review of the resulting code plus an
Severity: ❌ blocker / The final round found nothing: my own full-scope cold re-derivation of the diff (23 Session id: cron:clickhouse-review-slot-9:20260831-083300 |
Pre-PR validation gate (click to expand)
Capture validated on the failing job's own TSan binary (build id The ASan skip is driven over every reachable build type with a negative control that Session id: cron:clickhouse-review-slot-9:20260831-083300 |
|
Workflow [PR], commit [ebed802] Summary: ✅ AI ReviewSummaryThis PR fixes the Findings❌ Blockers
Final VerdictChanges requested. The extra diagnostics are useful, but the pre- LLVM Coverage Report |
|
cc @leshikus, could you review this? |
| if Path(self.DMESG_LOG).exists() | ||
| else self.DMESG_LOG | ||
| ) | ||
| if not Shell.check(f"dmesg > {dmesg_target}", verbose=True): |
There was a problem hiding this comment.
This now runs on every all=True failure, but all=True also became reachable before CH.start() runs at all (functional_tests.py:1507). On the install / start_seaweedfs / start_azurite failure paths, start() never executed the dmesg --clear at clickhouse_proc.py:349-351, so this uploads the host's uncleared kernel ring buffer from previous jobs and unrelated host activity. That is a new cross-job information disclosure surface, and it can also misattribute an older OOM to the current setup failure.
Please gate the dmesg capture on a flag that is set only after start() successfully clears the buffer, or skip uploading dmesg for failures that happen before that point.
There was a problem hiding this comment.
The reachability is right, and it is already disclosed. functional_tests.py:1019-1021 returns before CH.start() at :1022, so dmesg --clear never runs on the install, seaweedfs or azurite paths. The description lists it under what this does not fix ("a failure before start dumps an uncleared ring buffer"), and row 6 of the adjudication comment covers it together with both remedies suggested here.
I am not gating the capture. Nothing grades that dump: check_ch_is_oom_killed has a single caller, check_fatal_messages_in_logs (clickhouse_proc.py:1183), and all three of its call sites need test results (functional_tests.py:1186 and :1339 sit inside if is_bugfix_validation:, which dereferences test_result.results at :1182; :1491 sits under the if test_result and ... gate at :1485). So no OOM in dmesg verdict is reachable on the pre-start path, and the residual is a human reading an artifact the description already labels.
Skipping the upload instead would remove the artifact on the one path this change exists to serve, which is the defect being fixed. Clearing the buffer earlier destroys pre-job host history and needs privilege the sibling call takes with sudo.
69b2d1b
Related: #110321 (comment)
Related: #115585
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
A stateless job that fails during setup now uploads the same diagnostics as one that fails during tests.
Description
Stateless tests (amd_tsan, flaky check)on #110321 failed before any test ran:prepare_stateful_datahit its per-statement bound onINSERT INTO test.hits_s3 SELECT * FROM test.hits(report).
Its diagnostics were then discarded.
@ alexey-milovidovasked me for a separate PR.functional_tests.pyassignstest_resultonly inside the test stage, so a setup failureleaves it
None,test_run_failedreadsFalse, andprepare_logsruns withall=False-dropping cores, system-table dumps, the SeaweedFS log, dmesg and Keeper logs, for exactly
the runs that cannot explain themselves. Here
job.loglogssend TRAP signal to generate core fileandCollect logsin the same second. The shape covers 45+ stateless runs in 30 days.#115585 got such a job to reach
Collect logs; this makes it collect.Four changes, all under
ci/:gdb -batch -ex 'thread apply all backtrace'into the log directory when a prepstatement hits its bound; skipped on ASan lanes, where the attach disables LeakSanitizer;
timeout's own TERM diagnostic before trusting exit 124, which is also theerror code
INCORRECT_ELEMENT_OF_SET;dmesgin the full-collection path, where nothing did: a setup failure gainsdmesg.log, and a run whose OOM check already graded one gainsdmesg.at-collect.logbeside it, because
startclears the buffer per server generation.Green runs are unchanged.
This does not fix the hang; it makes the next occurrence diagnosable. Also not
fixed: the fatal-log scan still skips setup failures; a failure before
startdumps anuncleared ring buffer;
stop_serverstill waits 10 s afterSIGTRAP, so a core may notsurvive; the gdb attach is argued from container flags, not measured in-container; ASan lanes
get no stacks.
#109745edits the same function without overlap.The hang this PR does not fix
Measured from the job's own
clickhouse-server.log. The INSERT(
22411ddf-da0f-4f93-90b6-c4a06af00f93) progresses normally for 35.4 s, writing blocks andcompleting S3 uploads at 8.00 GiB of tracked memory against an 85.25 GiB cap. Then the server
emits nothing at all for 62.0 min, from any of the 186 threads that had ever logged, and the
last line of the log is an unfinished
SystemLog (system.query_metric_log): Flushing system log. Of 18 system logs, onlymetric_logandquery_metric_loghave an unmatchedFlushing.--max_execution_time 1800never fired, so the query threads were blocked ratherthan slow;
SYSTEM FLUSH LOGSafterwards returnedCode: 209 SOCKET_TIMEOUTafter the full300 s receive timeout;
SIGTERMwas ignored for 300 s. TERM landed at exactly +3150 s, thebound from #115585, to the second.
Truncation is ruled out: the file ends on a complete line at 3.43 MB with no
.zstsibling,and jobs at the same commit uploaded 59.7 MB and 9.96 MB logs spanning their full durations.
Same-commit, same-binary controls for the identical statement:
amd_tsan parallel133 s,amd_tsan sequential277 s,amd_asan_ubsan flaky check789 s, against >3150 s here.A merely slow INSERT logs continuously. A server that answers no new query is globally
blocked, and naming the mechanism needs a thread stack, which no occurrence has produced -
7 in 90 days, none with a core or a
fatal.log. That is what this PR adds.Workflow [PR]
Sync PR [sync-upstream/pr/117294]