Repository navigation
Never destroy the SymbolIndex singleton - #133152
Conversation
`SymbolIndex::instance()` kept the index in a function-local static. Static destructors run in reverse order of construction completion, and the index is built after `HandledSignals::instance()` (by the signal listener thread or by the first stack trace), so `~SymbolIndex` ran before `~HandledSignals`. When `~HandledSignals` logs an exception (`test_shutdown_static_destructor_failure` does this with the `lazy_pipe_fds_fail_close` failpoint), `tryLogCurrentException` formats the stack trace, `StackTrace::forEachFrame` calls `SymbolIndex::instance()`, and the guard returns the already destroyed object. MemorySanitizer reports the read of its destroyed `data.objects` (use-after-dtor, `poison_in_dtor=1`). Without MSan libc++'s `~vector` leaves `begin == end`, so nothing is read and no other sanitizer sees it. Leak the index instead, as `ErrorRegistry::get()` and `DateLUT::getInstance()` already do: every static destructor that symbolizes a stack trace during shutdown now reads a live index, whatever the construction order. This also covers `instanceIfInitialized()`, which could hand out a dangling pointer after `~SymbolIndex`. The report is old: it reproduces on the CI MSan binary of 4d1c0cd (glibc, before the background index build of ClickHouse#131638 and before the static musl build of ClickHouse#109239). It became visible on master only when ClickHouse#132826 taught the integration harness to detect MemorySanitizer reports; with this fix that detector can stay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own cold review of the diff (0 code findings). Checked: the leaked-singleton idiom matches Session id: cron:clickhouse-review-slot-11:20261120-073701 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261120-061321 |
|
Workflow [PR], commit [ef1ace7] Summary: ✅
AI Review
|
|
The link is wrong, correct one - https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=0a1face7467f9a047ca246fb29f31361a3b7f71e&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%208%2F8%29 @groeneai Do not respond to me anything, if you want you can just react on the message |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
3ca8f41
Related: #132826
Related: #133062
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Integration tests (amd_msan, 8/8)/test_shutdown_static_destructor_failurefails on every master run since #132826 taught the harness to detect MemorySanitizer reports: a use-after-dtor ofSymbolIndexin~HandledSignalsat exit. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=0a1face7467f9a047ca246fb29f31361a3b7f71e&name_0=MasterCI&name_1=Integration%20tests%20%28amd_msan%2C%208%2F8%29Root cause:
SymbolIndex::instance()held the index in a function-local static. The index is built afterHandledSignals::instance()(by the signal listener thread or the first stack trace), so~SymbolIndexruns first. The test enableslazy_pipe_fds_fail_close, so~HandledSignalslogs an exception, and formatting its stack trace callsSymbolIndex::instance(), which returns the destroyed object. Only MSan sees the read, because libc++'s~vectorleavesbegin == end.Change: leak the index, as
ErrorRegistry::get()andDateLUT::getInstance()already do, so any static destructor that logs a stack trace reads a live index. This also coversinstanceIfInitialized(). The index stays reachable, so LeakSanitizer does not report it.The report is old: it reproduces on the CI MSan binary of
4d1c0cdc17, which predates #131638 and #109239. With this fix the detector from #132826 can stay.Validation on a local MSan build (
--count 3): without the change each of the 3 shutdowns writes the report and the test fails in teardown with CI'sSanitizer assert found for instance; with it, no report and 3/3 pass. A standalone repro of the same shutdown reports 3/3 on two CI binaries and 0/5 with the change.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/133152]
Version info
26.12.1.38-master(included in26.12and later)