Repository navigation
Tolerate non-UTF-8 bytes when the integration harness decodes captured output - #118195
Conversation
…d output
`docker.log` is a multiplexed capture of every container's stdout and stderr, so
non-UTF-8 content is expected by construction: sanitizer reports, binary noise
and truncated multi-byte sequences all land there. One such byte was enough to
abort integration-test teardown:
helpers/cluster.py:4460 in shutdown
for line in f:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 1655
This is a split-handle regression. Before `3deae2dc5d90f6d0` (2025-02-14),
`shutdown` used a single handle for both directions: it opened
`docker_logs_path` as `"w+"` with `errors="replace"`, wrote the captured logs
through it, then rewound and iterated that same `TextIOWrapper`, so the read
carried the error handler. That commit moved the capture into `save_logs` as a
`Popen` writing to a tolerant handle, and gave the scan its own
`open(..., "r")` with no `errors=`. Because a subprocess writes to the raw file
descriptor, the write-side handler never runs on those bytes: the tolerance that
mattered was on the read side, and only the read side lost it.
`c5db8d74126cec70` (2025-02-17) then relocated that reader, which is why
`git blame` points there.
The statement that raises is the fallback sanitizer detector, reached only when
the per-instance `stderr.log` scan found nothing, and nothing catches it. So
teardown abandons `cleanup`, the `docker_net_lock` release, the Keeper
`stderr.log` scan, the raise for a sanitizer report, and the raise carrying the
`<Fatal>` and `LOGICAL_ERROR` findings gathered earlier in the same function. A
genuine server abort is then replaced in the report by a decode error, and since
raw sanitizer output is itself a prime source of non-UTF-8 bytes, this scan is
likeliest to die exactly when it has something to find.
Four sites change, chosen by one rule: the decoded text is only interpolated
into a message or scanned for an ASCII marker, so a strict decode there has no
upside and can only turn a diagnostic into a decode error.
- `shutdown`, the `docker.log` sanitizer scan.
- `run_and_check`, which re-decoded `res.stderr` strictly for its exception
message although `err` above it already holds those same bytes decoded
tolerantly. It now reuses `err`, which removes a decode rather than adding
tolerance.
- `wait_for_start`, both startup-failure messages, which interpolate
`handle.logs` and so died on the very output they exist to report.
Sites where the decoded value is the caller's own datum are deliberately left
strict, because tolerating bad bytes there could substitute U+FFFD for content a
test legitimately checks, and so mask a real defect. `errors="replace"` is
already the idiom for this in the same function, at the Keeper `stderr.log` scan.
Verified both directions at each site, with the statements taken from the tree
rather than retyped, and by driving `shutdown` over a dirty `docker.log` that
contains a sanitizer report: it now raises `Sanitizer assert found for instance
node3`, where that report was previously lost. Reverting any one of the four
edits reddens only its own arm, and behaviour on clean input is unchanged.
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review (click to expand)An independent cold review plus two adversarial gate rounds on
💡 Noted, not blocking. The commit message names |
|
Workflow [PR], commit [04efc5e] Summary: ✅ AI ReviewSummaryThis PR hardens the integration-test harness against non-UTF-8 bytes in diagnostic-only decode paths and fixes the remaining Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit 04efc5e.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +822 lines in 230 files (-1033 lines lost coverage) · Details |
|
cc @mstetsyuk, could you review this? The |
`ClickHouseCluster.shutdown` has three sanitizer-detection paths and only two of them respect its `ignore_sanitizer` argument. The per-instance `stderr.log` scan and the Keeper `stderr.log` scan are both gated on `not ignore_sanitizer`; the `docker.log` fallback sitting between them is unconditional, so it can set `sanitizer_assert_instance` and trip the unconditional raise at the end of `shutdown` even when the caller asked for sanitizer reports to be ignored. Two finalizers pass that argument deliberately and rely on it: tests/integration/test_keeper_sanitizer_logs/test.py:19, which injects a sanitizer marker on purpose, and tests/integration/test_crash_log/test.py:36. The gap predates this branch. It dates to 291dd76, which introduced `ignore_sanitizer` and gated the per-instance scan only. Measured by driving the real `shutdown` over five `docker.log` fixtures with `ignore_sanitizer=True`: on master 4 of the 5 raise, and the clean-bytes fixture raises `Sanitizer assert found` despite the caller asking to ignore it. The tolerant decode from the previous commit lowers that to 3 of 5, so it narrows the gap rather than widening it, but does not close it. With this guard all 5 complete. With `ignore_sanitizer=False` all three sign-bearing fixtures are still detected and the two sign-free ones still raise nothing, so no sanitizer signal is lost. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Backporting to fix CI |
Backport #118195 to 26.7: Tolerate non-UTF-8 bytes when the integration harness decodes captured output
Backport #118195 to 26.8: Tolerate non-UTF-8 bytes when the integration harness decodes captured output
… integration harness decodes captured output
Related: #117974
One non-UTF-8 byte in
docker.logaborts integration-test teardown and takes the sanitizer scan down with it.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Integration-test harness: tolerate non-UTF-8 bytes when decoding captured container output, so a single bad byte no longer aborts cluster teardown and the sanitizer scan, and honor
shutdown(ignore_sanitizer=True)in thedocker.logfallback scan.Description
Observed.
test_unknown_config_option/test.py::test_graphite_default_rule_type_not_all_rejectedpassed, then failed in teardown withUnicodeDecodeError: 'utf-8' codec can't decode byte 0x8a in position 1655athelpers/cluster.py:4460(CI report).Root cause: a silently reverted fix. #74334 fixed this same
UnicodeDecodeErrorinshutdownby addingerrors="replace"to the single handle used for both directions.3deae2dc5d90f6d0(2025-02-14) then split it: capture moved intosave_logs, and the scan got its ownopen(..., "r")with noerrors=. The keyword travelled with the write half, where a subprocess writes to the raw descriptor and the handler never runs, so only the side that mattered lost it.Cost. That statement is the fallback sanitizer detector and nothing catches it, so teardown also abandons
cleanup. Raw sanitizer output is itself a prime source of non-UTF-8 bytes, so the scan is likeliest to die when it has something to find.Scope. Two commits. The first restores tolerance at four sites, chosen by one rule: the decoded text only reaches a message or an ASCII-marker scan. Sites where the decoded value is the caller's datum, such as
get_container_logs, stay strict, since tolerating bad bytes there could mask a defect. The second closes an adjacent gap raised in review: of the three sanitizer scans inshutdown, only thedocker.logfallback was not gated onnot ignore_sanitizer, so it could raise even when the caller asked to ignore reports. That gap predates this branch (291dd76d7739487).Validation. Each decode site was exercised both directions over a
0x8afixture; reverting any one edit reddens only its own arm. Driving the realshutdownover five fixtures withignore_sanitizer=True: master raises on 4 of 5, the decode fix alone on 3 of 5, with the guard 0 of 5. Withignore_sanitizer=Falseall three sign-bearing fixtures are still detected, so no signal is lost. CIDB: one occurrence in 90 days, none onmaster.Workflow [PR]
Sync PR [sync-upstream/pr/118195]
Version info
26.9.1.1356-master(included in26.9and later)26.8.25.12,26.7.28.9