Skip to content

Collect leaked ASan fake frames at the top of the FunctionsStress worker loop - #126210

Merged
Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/functions-stress-asan-fake-stack-gc
Oct 20, 2026
Merged

Algunenano merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/functions-stress-asan-fake-stack-gc

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

FunctionsStress.stress frees the ASan fake-stack frames that exceptions leave behind in its worker threads, so range iterations no longer stall in the ASan build.

Description

Unit tests (asan_ubsan, function_prop_fuzzer) failed with 1 threads got stuck on range(...) in 9 runs on 2026-10-15, for example master 8f4f38d7. Every failure was in a build compiled with -fPIE (#125488): 0 of 343 -fPIC runs vs 23 of 388 -fPIE runs with a stuck thread or a range iteration over 12 s.

With detect_stack_use_after_return, frames unwound by an exception stay on the thread's fake stack. They are freed only by the first fake-frame allocation after the throw, and only if they are below it, but that allocation is libcxxabi's scan_eh_tab searching for the handler, below the throw site. The workers throw on most of their ~15M overload attempts per run, so size classes fill up. A full class makes each allocation from it scan all of its slots (8192 in class 1). Since #125488, IFunctionOverloadResolver::getReturnType leaks into the class that IColumn::assertTypeEquality takes on every compareAt, so range's per-element result checks stall.

At the top of every iteration the worker now calls __asan_handle_no_return and allocates one fake frame from a small helper, which frees every frame left by earlier iterations. Other builds get an empty function.

Validation on an ASan build of master, 600-s runs, CI options: without the change, size classes 1, 3 and 4 fill up in 8 of 8 runs, and one run of 9 reproduced the failure (Thread is stuck for 344.0s ... range(CAST(1192683 AS UInt32)), stuck in __asan_stack_malloc_1 under assertTypeEquality). With the change, no class holds more than 97 slots and 24 runs had 0 stuck threads. Overload attempts went up 24%, and the fake-stack share of CPU dropped from 32% to 14%. CI has had no such failure in 199 runs since 20:30 UTC on 2026-10-15, but passing runs still log 13-88 s range iterations.

Related: #125488
Related: #126137


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

Version info

  • Merged into: 26.11.1.304-master (included in 26.11 and later)
  • Backported to: 26.10.3.8

…ker loop

With detect_stack_use_after_return (on by default), every instrumented frame
with an address-taken local lives on a per-thread fake stack. A frame unwound
by an exception is not released: __asan_handle_no_return only sets needs_gc_,
and the next fake-frame allocation frees only the slots whose real_stack lies
below its own. The stress workers throw on most of their ~15M overload
resolution attempts per run, and the first allocation after the catch usually
comes from a frame deeper than the leaked ones, so the leaked frames survive.
Size classes 3 and 4 fill up on every worker within a minute, and class 1
fills with IFunctionOverloadResolver::getReturnType frames since ClickHouse#125488 moved
that frame from class 2 to class 1. A full class makes every allocation from it
scan all 8192 slot flags. IColumn::compareAt calls assertTypeEquality, which
takes a class-1 frame, once per element, so the per-row determinism checks of
range() over a few hundred thousand elements take minutes and the watchdog
reports the thread as stuck.

Calling __asan_handle_no_return and then allocating a fake frame from a small
helper at the top of every iteration runs FakeStack::GC from just below run(),
above every frame a previous iteration created, so all leaked slots are freed.
The helper's real frame is smaller than those of the loop's callees, so their
leaked frames lie below the GC point. Leaked frames are dead and GC poisons
them, so use-after-return detection is unchanged. Other builds compile an
empty function.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ No deterministic test proves the hook reclaims fake frames DISAGREE Both directions were measured locally with a gdb probe of each worker's fake stack: without the change a size class 1-4 is full in 8 of 8 600-s runs, with it no class holds more than 97 slots, and the same tree without the call fills classes 1, 3 and 4 again. This fixes the function fuzzer itself, so it ships no self-test; such a test would pin compiler-rt internals.
2 💡 The commit message says the post-throw GC point usually comes after the catch AGREE, not blocking It is libcxxabi's scan_eh_tab (built with ASan here) during the handler search, below the throw site; the PR description says so.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261016-050000

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [df38bde]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) FAIL
05345_text_index_prewhere_read_step_order FAIL cidb IGNORED
02346_non_negative_derivative NOT_FAILED cidb IGNORED
03174_exact_rows_before_aggregation NOT_FAILED cidb IGNORED
02151_hash_table_sizes_stats_joins_reordered NOT_FAILED cidb IGNORED
02884_create_view_with_sql_security_option NOT_FAILED cidb IGNORED
01414_push_predicate_when_contains_with_clause NOT_FAILED cidb IGNORED

AI Review

Summary

Adds an ASan-only cleanup hook between FunctionsStress worker iterations to reclaim fake-stack frames left by exceptions and prevent result-validation stalls. No actionable findings in PR head df38bde3436c458f1fb74dbc90d269f1d3afd0f6.

Missing context / blind spots
  • ⚠️ Independent execution validation was unavailable: this checkout has no local ClickHouse build, and the PR-head ASan build and function-fuzzer jobs are still pending. Regression evidence comes from the author's reported comparative stress runs; a completed ASan function-fuzzer job would close this gap.
Final Verdict

Status: ✅ Approve. No code changes requested; routine CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this and add can be tested? Since #125488 the ASan unit-test build fills the fake stack of the FunctionsStress workers with frames that exceptions left behind, so per-element range checks scan all 8192 slots on each call; the worker loop now runs ASan's fake-stack GC from its top on every iteration.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - df38bde

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05345_text_index_prewhere_read_step_order flaky, not from this PR (it changes only gtest_functions_stress.cpp): read_order_index_first 0 -> 1, because a remote parallel replica counts its reads on its own query_log row #125892 (mine, open)
Mergeable Check, PR rollups of the row above #125892 (the owner of the row above)

Session id: cron:our-pr-ci-monitor:20261016-100008

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice finding

@groeneai

Copy link
Copy Markdown
Collaborator Author

26.10 contains #125488 but not this fix, so the stuck range worker still fails FunctionsStress.stress in Unit tests (asan_ubsan, function_prop_fuzzer) on 26.10 backport PRs: 2 of 104 runs in the last 30 days (#126811, #127829, both stuck in range(...)). 26.9 and older do not contain #125488. The diff applies to 26.10 cleanly (line offsets only), so v26.10-must-backport here would cover it.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 26, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 26, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 26, 2026
Backport #126210 to 26.10: Collect leaked ASan fake frames at the top of the FunctionsStress worker loop
leshikus pushed a commit that referenced this pull request Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-functions Built-in SQL function implementations + function infrastructure. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-functions Built-in SQL function implementations + function infrastructure. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants