Skip to content

Revert "Revert "Build the symbol index in the background at server startup"" - #131638

Merged
Algunenano merged 6 commits into
masterfrom
revert-131562-groeneai/revert-131454
Nov 17, 2026
Merged

Algunenano merged 6 commits into
masterfrom
revert-131562-groeneai/revert-131454

Conversation

@Algunenano

@Algunenano Algunenano commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Reverts #131562


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

Version info

  • Merged into: 26.11.1.2627-master (included in 26.11 and later)

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [068c834]

Summary: ✅


AI Review

Summary

This PR restores background construction of SymbolIndex, reads the executable's build ID independently on ELF and Mach-O, and propagates index-construction exceptions to the main thread while preserving signal processing. Reviewed head 068c8343c5b1a30dd911ce665cb8ce3607ca15a3, including all prior discussion and the current diff. Both previous findings are addressed; there are no remaining actionable findings. Evidence includes the build-ID regression test, startup measurements in the original PR, and the author's recorded reproduction of the initialization failure. No local build or tests were run.

Final Verdict

Status: ✅ Approve

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

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 068c8343c with master 72bf27d8f (stripped binary size, per-symbol sizes and ThinLTO time; 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

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

Job report

…to the main thread

Now that the daemon reads its build id without the symbol index, the first build of
the index happens in `SignalListener::run`. When it throws (for example,
`CANNOT_PARSE_ELF` on a non-ELF `clickhouse.debug` next to the executable), the
exception left the listener thread and reached `KillingErrorHandler`, which hung the
startup for 300 s and then aborted the server (or, with `ServerErrorHandler`, left it
without signal processing).

Catch the exception in the listener, log it, keep processing signals, and hand it to
the main thread: `SignalListener::waitForTerminationRequest` wakes up and rethrows it,
so the server shuts down and exits with the original error code, as it did when the
index was built eagerly at initialization.

Checked with a non-ELF `clickhouse.debug`: the server exits with code 208
(`CANNOT_PARSE_ELF`) after 1 s, with the error in the log.

Related: #131548

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on ELF

On non-ELF platforms such as macOS, `SymbolIndex::getSelfBuildIDHex` has no way
to read the build id without the index and calls `SymbolIndex::instance`, so the
assertion in `SymbolIndexDeathTest.BuildIDWithoutTheIndex` always failed there.
The build id equality checks still run on every platform.

Related: #131638 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@Algunenano

Copy link
Copy Markdown
Member Author

Adding support for Darwin too, since it should be trivial

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI review approves this commit, see the AI Review comment.

@Algunenano
Algunenano added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit d8818c3 Nov 17, 2026
194 checks passed
@Algunenano
Algunenano deleted the revert-131562-groeneai/revert-131454 branch November 17, 2026 19:59
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 17, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Nov 20, 2026
`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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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