Repository navigation
Fix macOS crash capturing stack traces on fiber stacks - #111656
Merged
Algunenano merged 8 commits intoJul 24, 2026
Merged
Conversation
…, unify recovery in StackTrace ctor
Contributor
|
Workflow [PR], commit [3badd41] Summary: ❌
AI ReviewSummaryThis PR fixes the macOS/aarch64 fiber-stack trace fault by moving Missing context / blind spots
Final Verdict
|
alexey-milovidov
approved these changes
Jul 23, 2026
…e deadly-handler mask The deadly handler captures the crashed thread's stack via `StackTrace(ucontext_t)`, which now uses the shared thread-local unwind-fault recovery (`asynchronous_stack_unwinding` + `sigjmp_buf`). The profiler and `system.stack_trace` handlers already mask each other, but a pending `SIGUSR1`/`SIGUSR2`/`STACK_TRACE_SERVICE_SIGNAL` could still interrupt the deadly handler mid-unwind and clobber that buffer. Block them in the deadly-handler `sa_mask` via a new `additional_masked_signals` parameter of `addSignalHandler`. Co-Authored-By: Claude Fable 5 <[email protected]>
1 task done
…t shared unwind recovery
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 48/58 (82.76%) · Uncovered code |
Algunenano
enabled auto-merge
July 24, 2026 15:37
Merged
via the queue into
ClickHouse:master
with commit Jul 24, 2026
6e25534
176 of 178 checks passed
1 task done
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jul 26, 2026
Backport #111656 to 26.7: Fix macOS crash capturing stack traces on fiber stacks
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…stacktrace Fix macOS crash capturing stack traces on fiber stacks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a server crash (
SIGSEGVin Darwin's__thread_stack_pcs) on macOS/aarch64 when a stack trace is captured while a thread is running on aboost::contextfiber stack — for example the memory profiler sampling an allocation on the async reader of aremote(...)query.Root cause: macOS captures stacks with
backtrace(), a frame-pointer walk, and a fiber's saved frame-pointer terminator is left uninitialized bymake_fcontext, so the walk follows that junk off the fiber stack and dereferences an unmapped address. Linux is unaffected because it unwinds via CFI (libunwind), which stops at the fiber boundary. This became reachable on macOS when the profilers /trace_logwere enabled there (#109825); the memory profiler's synchronous capture is unguarded, so it crashes (the query profiler's signal-handler capture already had asiglongjmprecovery).Two changes:
contrib/boosttoclickhouse-1.90.0, which zeroes the fiber frame-pointer terminator in the arm64make_fcontext(aarch64: zero the fiber frame-pointer terminator in make_fcontext boost#47, merged). With a null terminator, any frame-pointer walker —backtrace()in the synchronous capture (StackTrace::tryCapture(), which must stay malloc-free for allocator hooks) and in the async-signal path,lldb,sample, the OS crash reporter — stops cleanly at the fiber boundary. This is the actual fix for the crash.asynchronous_stack_unwindingflag +sigsetjmp/siglongjmp) into theStackTrace(ucontext_t)constructor, replacing the copies hand-rolled inQueryProfiler.cppandStorageSystemStackTrace.cpp, so every asynchronous capture (query profiler,system.stack_trace, and the crash handler) recovers from a fault mid-unwind by dropping the capture instead of crashing. All handlers that share this thread-local recovery state — the profilers,system.stack_trace, and the deadly-signal handlers — now mutually block the corresponding signals (SIGUSR1,SIGUSR2,STACK_TRACE_SERVICE_SIGNAL) in theirsa_maskso they cannot nest and clobber the sharedsigjmp_buf.Validated on macOS/aarch64: reproduced the crash with the memory profiler on
remote()fiber reads, then confirmed it is gone with the fix (no crash under sustained stress; completeMemorySampletraces on fibers). A standalone reproducer built against the real boost fcontext asm showsbacktrace()faulting on a fiber stack while both the patchedmake_fcontextand CFI unwinding walk it cleanly.The crash cannot carry an automated regression test: it reproduces only on macOS/aarch64, where CI runs no bugfix-validation jobs. CI evidence of the crash from
Fast test (arm_darwin)(see #111579 for the full CI history — 20Server diedfailures across 20 PRs): https://s3.amazonaws.com/clickhouse-test-reports/PRs/109356/87764df278d5fc907268a6188b6b29dc2450c658/fast_test_arm_darwin/clickhouse-server.err.log.zstThe stopgap #111595 disabled the query and memory profilers on macOS to unblock the
Fast test (arm_darwin)CI; once this lands, that can be reverted to re-enable them.Closes: #111579
Related: ClickHouse/boost#47
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash on macOS (aarch64) when a stack trace was captured (for example by the memory profiler) while running on a coroutine/fiber stack.
Version info
26.8.1.97(included in26.8and later)26.7.2.20