Repository navigation
Keep the function name of a stack frame attributed to a libc++ __functional header - #112152
Conversation
…l` header
`collapseDemangledNames` replaced a frame's name with `?` whenever the frame's
source location was a file in a directory ending in `functional`. The intent was
to hide `std::function` plumbing frames, whose demangled names spell out the whole
captured lambda type and say nothing the neighbouring frames do not already say.
But the file of a frame is the source line the *instruction* maps to, which is not
necessarily where the enclosing function is defined. An ordinary function can have
individual instructions attributed to a libc++ `__functional` header - an inlined
`std::function` operation, or compiler-generated code reported with line 0 - and
then its name was dropped too, which loses the only useful part of the frame.
Require the symbol to be a libc++ one as well. `std::function` trampolines are
still displayed as `?`, exactly as before; an ordinary function keeps its name.
This is much more likely in a build with ThinLTO enabled, where `std::function`
calls are inlined across translation units, so it went unnoticed: `amd_cfi` is the
only integration-test build with ThinLTO on, and its `test_crash_log` failure is
what surfaced it. In that build, the frame that actually terminated the server was
displayed as
8. contrib/llvm-project/libcxx/include/__functional/function.h:0:7: ? @ 0x1c01f41f
in the fatal log and in `trace_full` in `system.crash_log`, where `0x1c01f41f` is
inside `DB::executeQuery`. Release builds also use ThinLTO, so the same frames were
being anonymised for users.
`collapseDemangledNames` becomes a static member of `StackTrace` so that the
heuristic is unit tested in every build, not only in the weekly ThinLTO job.
Fixes `test_crash_log/test.py::test_crash_log_extra_fields[terminate_with_exception-trace_full]`
and `[terminate_with_std_exception-trace_full]`, seen in
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b05161aa67d75ad84151a392f3e87156efd42842&name_0=WeeklyCFI&name_1=Integration%20tests%20%28amd_cfi%2C%202%2F4%29
|
Workflow [PR], commit [0fb79aa] Summary: ✅
AI ReviewSummaryThe PR narrows Final Verdict✅ No review findings in the current diff. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 81/82 (98.78%) · Uncovered code |
…g itself The heuristic required the symbol to start with `std::`, which still dropped the name of a meaningful libc++ frame that lives in a `__functional` header - libc++ puts `std::hash`, `std::less` and friends there too, so a crash inside `std::hash<String>::operator()` was displayed as `?`. Match the type-erasing wrappers of `std::function` and the invoke helpers they forward through by name instead, and keep every other symbol named.
…tional-name-suppression
…tional-name-suppression
`std::__invoke`, `std::invoke`, and `std::__mem_fn` are generic C++ call wrappers, not `std::function`-specific plumbing, and their frames can name the callable they dispatch to. Suppressing them recreated the "lost the only informative frame name" bug for direct `std::invoke` / `std::mem_fn` paths. Keep only the type-erasing wrappers of `std::function` in the suppression set. Co-Authored-By: Claude Fable 5 <[email protected]>
…tional-name-suppression
The `std::function<` prefix matched every member of `std::function`, so a frame of `std::function<...>::swap`, `target_type` or `operator bool` was still collapsed to `?` - the same "lose the only informative frame name" bug, for that part of the surface. Only the type erasure is noise: the call operator, the constructors and the destructor, which copy, move and destroy the captured callable. The member name is now read past the template argument list (nested `<`/`>` of the callable's signature are counted) and matched against that list. Adds `StackTraceCollapseNames.KeepsOrdinaryStdFunctionMembers` and cases for the constructor and the destructor.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 67/68 (98.53%) · Uncovered code |
…tional-name-suppression
|
🕵 Merged The only blocker for @groeneai, please take a look at #106237 and provide a fix in a separate PR if one is not already in progress; link it there if it is.
|
|
A fix is already in progress: #106251, open, waiting on one design decision about the memory bound of the queue-cap bypass. I have posted the current status on #106237. Your attribution of the |
…or frame The constructor of `std::function` that takes a callable is a function template, so after the outer `std::function<...>::` is stripped the member is spelled `function<MyCallable, void>(MyCallable&&)`, which the `function(` prefix did not match. Recognise `function<` as well, and add the corresponding gtest case.
…tional-name-suppression
…tional-name-suppression
The callable-taking `operator=` overloads are function templates, spelled `operator=<MyCallable, void>(MyCallable&&)` after the outer template argument list is stripped, so they kept the whole captured type visible even though they are the same type-erasing noise as the templated constructor. The copy and move assignment (`operator=(`) do the same work as the copy and move constructors, which were already hidden, so they are treated the same way. Regression cases added to `HidesStdFunctionPlumbing`.
|
🕵 The two stress-test reds on 1fb14fd are unrelated to this rendering-only change:
@groeneai, investigate the |
|
Investigated. The What the stack shows. The failing thread is a mutation background task, not a query:
Why the merged fixes do not cover it. #107924 rewrote The log supports that reading: two Carrier. The table is Frequency. Over 45 days, 394 rows carry this message; only 2 have I could not reproduce it deterministically yet - the plain mutation-plus- Tracking issue for the family is #107619. I will open the PR for this sink and link it here. |
|
Correction to my earlier comment, plus the actual root cause. I was wrong about the trigger. I attributed the abort to the two The trigger is
Why this sink and not Two defects, and neither is fixable alone.
Fixing only 2 relocates the exception rather than removing it: This is already fixed in your own #102308. It adds So I would rather not open a third PR over
I have the reproduction plan either way: slow Family tracking issue is #107619. |
…isible `operator=(` also matched the `std::nullptr_t` overload, which merely resets the object and has a short, informative name of its own, so a frame in `f = nullptr;` was still displayed as `?`. Spell the copy and move assignment as `operator=(std::function<` instead, and keep a regression case for the `nullptr` reset path. Co-Authored-By: Claude Fable 5 <[email protected]>
…tional-name-suppression
…tional-name-suppression
|
The fix is in #114463. Root cause is the mutation's interactive-cancel callback returning a bare The callback now throws One correction to my earlier comment on this thread: I said the fix needed both a #109722 does not cover this sink, so I have not linked it as the fix. |
…t-testability A pure refactoring with no behavior change: the function was file-local in `StackTrace.cpp`, compiled only under `#if (defined(__ELF__) && !defined(OS_FREEBSD)) || defined(OS_DARWIN)`; now it is a public static member declared in `StackTrace.h` and defined unconditionally. This unblocks `Bugfix validation (unit tests)` for ClickHouse#112152: the validation overlays the PR's new regression test onto the merge-base and requires it to compile there and fail at runtime, but the test calls `StackTrace::collapseDemangledNames`, which did not exist on the merge-base, so the "before" binary failed to compile and the validation was inconclusive: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112152&sha=c9b08639cb488c1a023376e2623d7b338748a89c&name_0=PR&name_1=Bugfix%20validation%20%28unit%20tests%29 Once this refactoring is in `master` and merged into that PR's branch, its "before" binary compiles the test against the old behavior and the test fails at runtime, turning the validation into a genuine reproduction. Co-Authored-By: Claude Fable 5 <[email protected]>
…tional-name-suppression
…t-testability A pure refactoring with no behavior change: the function was file-local in `StackTrace.cpp`, compiled only under `#if (defined(__ELF__) && !defined(OS_FREEBSD)) || defined(OS_DARWIN)`; now it is a public static member declared in `StackTrace.h` and defined unconditionally. This unblocks `Bugfix validation (unit tests)` for #112152: the validation overlays the PR's new regression test onto the merge-base and requires it to compile there and fail at runtime, but the test calls `StackTrace::collapseDemangledNames`, which did not exist on the merge-base, so the "before" binary failed to compile and the validation was inconclusive: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112152&sha=c9b08639cb488c1a023376e2623d7b338748a89c&name_0=PR&name_1=Bugfix%20validation%20%28unit%20tests%29 Once this refactoring is in `master` and merged into that PR's branch, its "before" binary compiles the test against the old behavior and the test fails at runtime, turning the validation into a genuine reproduction. Co-Authored-By: Claude Fable 5 <[email protected]>
…t-testability A pure refactoring with no behavior change: the function was file-local in `StackTrace.cpp`, compiled only under `#if (defined(__ELF__) && !defined(OS_FREEBSD)) || defined(OS_DARWIN)`; now it is a public static member declared in `StackTrace.h` and defined unconditionally. This unblocks `Bugfix validation (unit tests)` for #112152: the validation overlays the PR's new regression test onto the merge-base and requires it to compile there and fail at runtime, but the test calls `StackTrace::collapseDemangledNames`, which did not exist on the merge-base, so the "before" binary failed to compile and the validation was inconclusive: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112152&sha=c9b08639cb488c1a023376e2623d7b338748a89c&name_0=PR&name_1=Bugfix%20validation%20%28unit%20tests%29 Once this refactoring is in `master` and merged into that PR's branch, its "before" binary compiles the test against the old behavior and the test fails at runtime, turning the validation into a genuine reproduction. Co-Authored-By: Claude Fable 5 <[email protected]>
…ributed to a libc++ `__functional` header
Backport #112152 to 26.7: Keep the function name of a stack frame attributed to a libc++ `__functional` header
Backport #112152 to 26.5: Keep the function name of a stack frame attributed to a libc++ `__functional` header
…ently A mutation whose predicate contains `IN (subquery)` materializes the right-hand side through `FutureSetFromSubquery::buildSetInplace`, which runs a nested `CompletedPipelineExecutor` and polls the mutation's interactive-cancel callback. The callback returned a bare `bool`, so on cancellation the executor called `cancel()` and the poll loop returned normally: `CreatingSetsTransform::generate` and therefore `Set::finishInsert` never ran, leaving the set uncreated while `build()` had already moved the source plan out. `buildSetsForDAG` returns void, so `getMinMaxCountProjectionBlock` went on to evaluate the filter in the same call and `FunctionIn` threw "Not-ready Set is passed as the second argument for function 'in'" - a server abort in debug and sanitizer builds. Reported by @ alexey-milovidov on ClickHouse#112152 (comment) after a Stress test (amd_debug) run aborted this way. `DETACH DATABASE` during a running mutation is the trigger seen in CI; `KILL MUTATION` reproduces it. The callback now throws `ABORTED` on cancellation, mirroring `MergeTask::checkOperationIsNotCanceled`, which reports the merge path the same way and is likewise wired into nested pipelines. `MergeTreeBackgroundExecutor` already treats `ABORTED` as a normal outcome and logs it at DEBUG. Only the mutation installs this callback shape; the two interactive installers in `TCPHandler` and `LocalConnection` are untouched, so client-side cancellation still returns `QUERY_WAS_CANCELLED` quietly. Instrumented measurement of the cancel path before the fix: of three mutating parts, one returned from `execute()` with no exception and an uncreated set, while the other two observed the `UNKNOWN_EXCEPTION` that `~CreatingSetsTransform` sets on the shared promise - so the loud report was a race, not a contract. A readiness guard at the projection site was measured and deliberately not added: with the cancellation reported, no user-runnable input reaches that sink. Related: ClickHouse#107619 Co-Authored-By: Claude Fable 5 <[email protected]>
…ributed to a libc++ `__functional` header
Backport #112152 to 26.6: Keep the function name of a stack frame attributed to a libc++ `__functional` header
… frame attributed to a libc++ `__functional` header
Caused by: #57201
Related: #100419
collapseDemangledNamesreplaced a stack frame's function name with?whenever the frame's source location was a file in a directory ending infunctional. The intent was to hidestd::functionplumbing frames, whose demangled names spell out the whole captured lambda type and say nothing the neighbouring frames do not already say.But the file of a frame is the source line the instruction maps to, which is not necessarily where the enclosing function is defined. An ordinary function can have individual instructions attributed to a libc++
__functionalheader - an inlinedstd::functionoperation, or compiler-generated code reported with line 0 - and then its name was dropped too, which loses the only useful part of the frame.This PR requires the symbol to name the
std::functionplumbing as well: the type-erasing wrappers (std::__function::__func,__value_func,__policy_func, ...) and the type erasure ofstd::functionitself - itsoperator(), its copy, move and callable-taking constructors and assignment operators, and its destructor. The ordinary members ofstd::function(swap,target_type,operator bool, thenullptrresetoperator=(std::nullptr_t), the empty-constructingfunction()/function(std::nullptr_t), ...) do work of their own, so they keep their names too. Those are still displayed as?, exactly as before; every other frame keeps its name - not only an ordinaryDBfunction, but also a meaningful libc++ symbol that happens to live in a__functionalheader, such asstd::hash<String>::operator()from__functional/hash.h, or the generic invocation helpersstd::invoke/std::__invoke/std::mem_fn, which are notstd::function-specific and whose frames can name the callable they dispatch to.This is much more likely in a build with ThinLTO enabled, where
std::functioncalls are inlined across translation units, so it went unnoticed for a long time:amd_cfiis the only integration-test build with ThinLTO on, and itstest_crash_logfailure is what surfaced it. In that build, the frame that actually terminated the server was displayed asboth in the fatal log and in
trace_fullinsystem.crash_log, where0x1c01f41fis insideDB::executeQuery(the symbol resolves correctly - only the display suppressed it). Official release builds also use ThinLTO, so the same frames were being anonymised for users.collapseDemangledNamesbecomes a static member ofStackTraceso that the heuristic is covered by a unit test in every build, rather than only by the weekly ThinLTO job.Fixes
test_crash_log/test.py::test_crash_log_extra_fields[terminate_with_exception-trace_full]and[terminate_with_std_exception-trace_full], seen in https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=b05161aa67d75ad84151a392f3e87156efd42842&name_0=WeeklyCFI&name_1=Integration%20tests%20%28amd_cfi%2C%202%2F4%29Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a stack frame being displayed as
?instead of its function name in fatal log messages and in thetrace_fullcolumn ofsystem.crash_log. It affected frames of ordinary functions that have code attributed to a libc++__functionalheader, which is common in release builds.Version info
26.8.1.1334(included in26.8and later)26.7.4.44,26.6.3.58,26.5.7.57