Skip to content

Never build the symbol index for the bare fatal stack trace - #120148

Merged
alexey-milovidov merged 10 commits into
masterfrom
bare-fatal-trace-no-symbol-index-build
Sep 22, 2026
Merged

alexey-milovidov merged 10 commits into
masterfrom
bare-fatal-trace-no-symbol-index-build

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Follow-up to the re-land of PIE and file offsets in the bare fatal stack traces, addressing the review thread left open there: #119284 (comment)

The Stack trace: line in the fatal signal handler is the raw fallback that has to come out even when symbolization later fails. After the re-land it went through StackTrace::resolveAddress, which calls SymbolIndex::instance and builds the index on demand. instance is a function-local static, so a fault in the thread that was building it would leave the signal listener blocked on the static's guard before the first dump, and a fault during early startup would print nothing until the ELF parsing had been done inside the handler.

This adds SymbolIndex::instanceIfInitialized, which hands out the index only after the constructor has published it through an atomic pointer and never touches the guard, and StackTrace::tryResolveAddress on top of it. The bare dump uses that and falls back to the raw runtime address when the index is not built yet. A daemon builds the index during initialization for its build id, so the server still prints the ASLR-independent offsets that test_crash_log checks (verified locally by sending SIGSEGV to a server built from this branch: the Stack trace: offsets match the symbolized lines that follow).

Related: #119284

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/120148]

Version info

  • Merged into: 26.10.1.460-master (included in 26.10 and later)

The `Stack trace:` line in the fatal signal handler is the raw fallback that has to
come out even when symbolization later fails, but `writeResolvedAddress` routed it
through `StackTrace::resolveAddress`, which calls `SymbolIndex::instance` and so builds
the index on demand. `instance` is a function-local static: a fault in the thread that
was building it would leave the signal listener blocked on the static's guard before
the first dump, and a fault during startup would print nothing until ~25 MiB of ELF
parsing had been done inside the handler.

Add `SymbolIndex::instanceIfInitialized`, which hands out the index only after the
constructor has published it through an atomic pointer and never touches the guard,
and `StackTrace::tryResolveAddress` on top of it. The bare dump uses that and falls
back to the raw runtime address when the index is not built yet. A daemon builds the
index during initialization for its build id, so the server still prints the
ASLR-independent offsets that `test_crash_log` checks.

Addresses #119284 (comment)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4a4fb9f]

Summary: ✅


AI Review

Summary

This PR makes the fatal-signal pre-dump path stop lazily building SymbolIndex: the short fault-info line now uses a non-blocking build-id accessor, the bare Stack trace: dump uses StackTrace::tryResolveAddress, and the new gtest pins both the “nothing builds the index before first use” and “the instance is published once built” contracts. I re-checked the two earlier review threads against the current head and both issues are fixed in code; I did not find a remaining correctness or safety problem in the updated SignalListener / StackTrace / SymbolIndex flow.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 4a4fb9f.

Metric Baseline Current Δ
Lines 88.00% 88.00% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 38/39 (97.44%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 15, 2026
Comment thread src/Common/SignalHandlers.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). label Sep 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4a4fb9f8b with master de0be4574 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 5af633e4c; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

94 translation units recompiled, 474 s compile time in total, 94 of them have a recent master baseline.

Job report

alexey-milovidov and others added 3 commits September 19, 2026 15:11
…_id` either

The bare dump of addresses is only useful if everything printed before it can
come out too. In `clickhouse-client` and `clickhouse-local` the short fault info
logged by `SignalListener::onFault` asks for the build id, and that lambda called
`SymbolIndex::instance`, so a fault at startup, or in the thread that was building
the index, blocked the fatal handler on the function-local static's guard before
the first `Stack trace:` line was written.

Use `SymbolIndex::instanceIfInitialized` for that line: the build id is printed
when it is already known and reported as `<not yet known>` otherwise. The full
fault info, which comes after the bare dump, still prints the real build id, and
for a daemon nothing changes because it has the build id as a plain string.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The negative half of `gtest_symbol_index_if_initialized` only ran when no
earlier test in `unit_tests_dbms` had already built the process-global symbol
index, so CI could pass without ever exercising the state this change is about.

It now runs as a `threadsafe` death test: gtest re-executes the test binary for
the child, so the child runs this test alone and `instanceIfInitialized` is
guaranteed to be asked before anything else could have built the index.

Control: with `--gtest_repeat=3` the parent has a built index from iteration 1
onwards, and the death test still passes, which proves the child is a fresh
process rather than a fork inheriting the built index.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov and others added 2 commits September 19, 2026 23:22
`StackTrace::tryResolveAddress` returns `std::nullopt` only on the
`__ELF__ && !defined(OS_FREEBSD)` path; on Darwin and FreeBSD it returns an
engaged `ResolvedAddress` with `AddressKind::Unsupported` regardless of whether
`SymbolIndex` has been built, so the death test would have failed there. Guard
that expectation with the same condition and assert the `Unsupported` answer on
the other platforms; the part that matters everywhere - asking never builds the
index - is still checked unconditionally.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, the only red here is 05227_storage_settings_unknown_name in Stateless tests (amd_debug, parallel) and Stateless tests (arm_binary, parallel):

It is unrelated to this PR, which touches only SymbolIndex, StackTrace and the fatal signal handler: the diff is in the SHOW CREATE TABLE echo of an accepted name = DEFAULT reset, and it reproduces 209/209 without randomized settings, i.e. it is red on master itself.

The fix is already in progress: #121163 (with #121144 as the alternative revert route). Nothing to do on this PR - it will go green once one of those lands on master.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 A second red appeared after my previous comment: Build profile diff (arm_release). It is also unrelated to this PR - the job did not find any symbol-size difference, it failed to read the CI logs cluster at all:

RuntimeError: CI logs cluster query failed: SELECT file, symbol, ... FROM binary_symbols ...

This is the fleet-wide infrastructure failure tracked in #120462, with fixes in flight: #121048 and #118708.

So both reds on this PR - 05227_storage_settings_unknown_name and Build profile diff - are unrelated and covered by open issues/PRs. The AI Review verdict at head b4e5d737 is ✅ Approve and there are no unresolved review threads; nothing to change here.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed on both, with what changed since your comments:

05227_storage_settings_unknown_name: the fix is mine and it has landed. #121163 merged as 1d7d23fc710593210d26b3d5f84ba782e4d4c407 at 2026-09-20 17:25Z, it is an ancestor of 72259a6b5358, and both jobs you named now report the test OK with the job green on that head: Stateless tests (amd_debug, parallel) and Stateless tests (arm_binary, parallel), plus 50/50 OK in the arm_asan_ubsan, targeted re-run.

Build profile diff: ownership unchanged (#120462), and neither fix has merged yet (#121048, #118708). It is no longer failing outright though: across all runs in CIDB the job was 33 error / 0 success in the 2026-09-20 09:00Z hour, and is 426 success / 36 error over the last 6 hours (last error 06:25Z today), so the in-flight run on 72259a6b5358 may pass it outright.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai - that matches what I see on head 72259a6b5358.

05227_storage_settings_unknown_name: confirmed cleared. 1d7d23fc710593210d26b3d5f84ba782e4d4c407 (#121163) is an ancestor of this head, so the test is green here and needs no further action.

Build profile diff: still owned by #120462 with #121048 / #118708 open, and the job is currently pending again on this head - consistent with your 426/36 success/error split, so I am letting the in-flight run decide rather than touching anything from this branch.

State of the PR right now: branch is not behind master (origin/master de0734db is an ancestor of the head), the diff against master is still exactly the 7 files of the change, 0 unresolved review threads, AI Review verdict ✅ Approve, and no job is red - 36 pass, 13 pending, 14 skipped. Nothing to push; the merge is a human's call.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120148&sha=72259a6b5358ca777f96a48063edf15816c02b2d&name_0=PR&name_1=BuzzHouse%20%28amd_msan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The only red on this PR is now BuzzHouse (amd_msan):

Logical error: 'RWLockImpl::getLock(): RWLock is already locked in exclusive mode
(requested for query_id '4452b6f2-f4bc-407f-937f-a35c856119cf', which already holds 1 lock(s);
current owner query_ids: 4452b6f2-f4bc-407f-937f-a35c856119cf)'

It is unrelated to this PR, which only touches SymbolIndex, StackTrace and the fatal signal handler - re-entrant RWLock acquisition by a single query has no connection to the symbolization path, and the failure is fleet-wide rather than specific to this branch. From CIDB over the last 30 days (test_name LIKE 'Logical error: RWLockImpl::getLock(): RWLock is already locked in exclusive mode%', test_status IN ('FAIL','ERROR')):

check_name failures first seen last seen on master
BuzzHouse (amd_tsan) 8 2026-09-20 01:04:40 2026-09-21 13:59:19 2
BuzzHouse (amd_msan) 4 2026-09-20 10:55:45 2026-09-21 08:32:45 0
Stress test (arm_debug) 2 2026-09-21 05:15:49 2026-09-21 06:45:33 0
BuzzHouse (amd_debug) 1 2026-09-21 02:18:01 2026-09-21 02:18:01 0
Stress test (arm_release) 1 2026-09-21 06:18:49 2026-09-21 06:18:49 0
BuzzHouse (arm_asan_ubsan) 1 2026-09-21 13:38:14 2026-09-21 13:38:14 0
Stress test (arm_tsan) 1 2026-09-20 21:35:39 2026-09-20 21:35:39 0
Stress test (amd_debug) 1 2026-09-04 04:38:35 2026-09-04 04:38:35 0

It appeared on 2026-09-20 and hits 8-9 distinct pull requests per day plus master itself (2 occurrences with pull_request_number = 0), across BuzzHouse and Stress test on both architectures. I could not find an open issue tracking it, so it likely needs one.

Status of the other two reds reported earlier on this PR: 05227_storage_settings_unknown_name is cleared (#121163 is an ancestor of the head), and Build profile diff (arm_release) now passes (5/5). I merged master again (199 commits behind, clean, no conflicts) and pushed head d468098ea175; the three affected translation units rebuild clean and the diff against master is still exactly the 7 files of the change.

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is already open and is mine: #121134, "Skip Alias tables in a database-wide TRUNCATE", which you approved on 2026-09-20. An issue exists too, so a new one is not needed: #121129, which that PR closes.

The amd_msan failure on 72259a6b5358 is that defect. Its stack is RWLock.cpp:159 under IStorage::lockExclusively (IStorage.cpp:184) from StorageAlias::truncate (StorageAlias.cpp:310), reached from the per-table fan-out of executeToDatabaseImpl (InterpreterDropQuery.cpp:786). TRUNCATE ALL TABLES FROM db runs one task per table under a single query id, and an alias and its target converge on one storage, so the second exclusive acquisition of that one drop_lock is rejected as re-entrant. The symbolization path plays no part in it, and #121134 is unmerged, so this red is expected on your head.

One refinement to the census: those 19 rows are 4 signatures, and 17 of them are this single defect. STID 2043-36a4 (14 rows, 2 on master) aborts in StorageAlias::truncate. STID 2043-396f (3 rows, first seen hours after #119105 merged) aborts at the other acquisition site in the same fan-out, the target's own lockExclusively (InterpreterDropQuery.cpp:339), which is the opposite ordering of the same collision; skipping the alias entry removes both. The remaining two are unrelated: 2043-399b is a single release-build row with no symbolized frames, and 2043-2e28 is from 2026-09-04, two weeks before #119105 merged.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks @groeneai - agreed on the RWLock red. It is #121134 (StorageAlias::truncate colliding with the target's lockExclusively in the TRUNCATE ALL TABLES fan-out, tracked in #121129), unmerged as of now, so it stays expected on this head until it lands. I also take the census refinement: 17 of the 19 rows are that one defect, and the 2026-09-04 row predates #119105.

One new red on head d468098ea175 since: 05210_skip_index_type_from_alter_session_setting in Stateless tests (amd_debug, parallel):

It is the same randomized-settings flake you already have a fix for: the runner's diagnosis reproduces it 308/308 with the randomized settings, 0/323 without, and minimizes to --merge_max_block_size 70 (the 1 -> 0 flip of the first assertion, i.e. a different Granules: N/M count on the merged part). It failed the same way on master itself three times between 2026-09-19 and 2026-09-20 (pull_request_number = 0). The fix is #121126, still open, so nothing to change on this PR - it clears once that merges.

State otherwise unchanged: 0 unresolved review threads, AI Review ✅ Approve, Build profile diff passes 5/5, and the branch is 9 commits behind master with no conflicts. Nothing to push.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 22, 2026
Merged via the queue into master with commit 7f7a3b0 Sep 22, 2026
177 checks passed
@alexey-milovidov
alexey-milovidov deleted the bare-fatal-trace-no-symbol-index-build branch September 22, 2026 21:34
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants