Skip to content

Print the stack trace of a stuck worker in FunctionsStress.stress - #126137

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/functions-stress-stuck-worker-stack
Oct 16, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/functions-stress-stuck-worker-stack

Conversation

@groeneai

@groeneai groeneai commented Oct 15, 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 reports how long a stuck worker has been in its iteration and prints the stack trace of the first stuck worker.

Description

Between 2026-10-15 10:00 and 20:25 UTC, Unit tests (asan_ubsan, function_prop_fuzzer) failed with 1 threads got stuck in 9 of 332 runs (7 PRs and 2 master runs), against 0 of 1,798 runs in the three days before; the MSan and TSan lanes had no such failure. Every report names range, for example PR #121704 and master 8f4f38d7: Thread is stuck while re-resolving and re-executing: SELECT range(materialize(CAST(9234215 AS Int32)));. That query takes under a second on its own, and the log carries nothing else, so the stall cannot be located from CI.

On stuck detection the main thread now sends STACK_TRACE_SERVICE_SIGNAL to the first stuck worker while holding its mutex, so the worker cannot leave the reported step. A handler installed by the test copies StackTrace(ucontext) for that thread only; the main thread waits up to 10 s and prints one line per frame: the offset in unit_tests_dbms (for llvm-symbolizer --obj), or in the named shared library, and the demangled name. It only reads the symbol index, which is built at test start, so a stuck thread holding symbolization locks cannot block the report. It is skipped where hasAsyncSignalSafeUnwind() is false (TSan). Each stuck line also gets the iteration age.

Validation (ASan+UBSan): with a temporary infinite loop in identity, the report shows Thread is stuck for 35.0s while executing: ... and a stack whose top offset symbolizes to the loop line; a sleeping loop shows clock_nanosleep; without this change the same run prints only the query. Full 600-s runs with the CI options pass. In one of 26 such runs a range(CAST(1532863 AS UInt32)) iteration took 116 s, so the slow range case does reproduce locally, but too rarely to bisect; this PR does not fix it.


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

Version info

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

groeneai and others added 2 commits October 15, 2026 20:37
A stuck-worker report printed only the query of the step the worker was in,
so a stall whose location does not follow from the query could not be
located from CI. Since 2026-10-15 the asan_ubsan function_prop_fuzzer job
fails this way on `range` in about 3% of runs, with queries that take well
under a second on their own.

On stuck detection the main thread now sends STACK_TRACE_SERVICE_SIGNAL to
the first stuck worker while still holding its mutex, so the worker cannot
move to another step between the copy of `operation` and the capture. A
handler owned by the test copies StackTrace(ucontext) for that one thread
(identity check on pthread_self, as on the macOS path of system.stack_trace)
and sets an atomic; the main thread waits up to 10 s, then prints one line
per frame with the ASLR-independent offset from tryResolveAddress, for
llvm-symbolizer against the job's unit_tests_dbms, and the demangled name
from SymbolIndex::instanceIfInitialized()->findSymbol. StackTrace::toString
is not used: it takes the stack-trace cache locks and SymbolIndex::instance,
which the stuck thread may hold. The symbol index is built on the main
thread at test start, before any worker exists, so names resolve even when
no exception has built it yet.

The handler stays installed for the rest of the process: the signal is not
in HandledSignals::handled_signals, so HandledSignals::reset never sets it to
SIG_DFL, and a delivery after the timeout fails the identity check and
returns. Skipped where hasAsyncSignalSafeUnwind() is false (TSan), and on
non-Linux builds; those keep the report with only the new iteration age.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
For a frame outside unit_tests_dbms, StackTrace::tryResolveAddress returns
an offset inside the shared object it names, so a bare offset was
misleading. Append the object the same way the fatal-signal handler does
(writeResolvedAddress in SignalHandlers.cpp): " in <object>" for another
loaded object, " in <unknown>" for an unmapped address.

StackTrace(ucontext) returns an empty trace when the unwinder faults, which
was printed as a stack header with no frames. Report it as a failed unwind.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds: 2 fixed, 1 declined, 0 open)
Finding Verdict
⚠️ Shared-library frames were printed as bare offsets, indistinguishable from unit_tests_dbms offsets Agreed, fixed: the object name is appended, as in the fatal-signal dump
⚠️ A recovered unwind fault printed an empty stack block Agreed, fixed: reported as "Could not unwind the stack of the stuck thread"
💡 No test covers the stuck-report path Declined: no tests for the test harness itself; checked locally with a temporary stuck loop, with and without the change
💡 The symbol index is also built at test start under TSan, where no stack is captured Noted, not blocking: it would be built by the first symbolized exception of the run anyway

Round 2 (after the fixes): no findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? For what this PR changes, yes: a temporary infinite loop in identity (--functions=identity --threads=2 --duration=5) makes both workers stuck on every run. The slow range iteration itself is not deterministic: 9 of 332 CI runs since 2026-10-15 10:00 UTC, once in 26 local full runs (116 s).
b Root cause explained? The stuck report printed only the query and detached the thread, so a stall whose location does not follow from the query (range on at most 23M elements, normally 2-8 s) could not be located from CI.
c Fix matches root cause? Yes: it adds the missing artifact (iteration age and stack of the stuck thread) where the harness detects it. No cap on range inputs, which would only hide the case from the fuzzer.
d Test intent preserved / new tests added? The verdict is unchanged (still N threads got stuck). Test-infrastructure change, so no self-test; validated locally (rows a, e).
e Both directions demonstrated? Without the change: Thread is stuck while executing: SELECT identity(...) only. With it: Thread is stuck for 35.0s while ... plus a stack whose top offset symbolizes to the loop line (llvm-symbolizer --obj=unit_tests_dbms); a sleeping loop shows clock_nanosleep.
f Fix is general across code paths? Single stuck-detection site. Builds without async-signal-safe unwinding (TSan) and non-Linux builds keep the age-only report.
g Fix generalizes across inputs (params/datatypes/wrappers)? Spinning and sleeping workers verified; several stuck workers give one stack (the first); a late answer after the 10 s timeout is ignored by the thread check and the handler stays installed; an unwind fault prints Could not unwind the stack of the stuck thread; shared-library frames carry the object name.
h Backward compatible? (maintainer-approved exception only) Test-only; no settings, formats or behavior outside the failing path.
i Invariants and contracts preserved? Green runs never reach the path (26 full runs, no stack line). The handler allocates nothing, takes no lock and saves errno; the main thread reads the copy only after the release store; the worker cannot exit while the main thread holds its mutex.

Session id: cron:clickhouse-impl-slot-4:20261015-181800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this? When FunctionsStress.stress detects a stuck worker, it now signals that worker and prints its stack trace (offsets plus symbol names) and the iteration age. Since 2026-10-15 the asan_ubsan lane fails on a stuck range iteration that CI logs cannot locate. This PR does not fix that, it makes the next occurrence carry a stack.

@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0bb0a2f]

Summary: ✅


AI Review

Summary

The PR adds iteration age and a bounded stack capture for the first stuck worker in FunctionsStress.stress, with object-qualified frame offsets and symbol names. Reviewed head: 0bb0a2feb008216787f004542a511cd757a3360e. No actionable findings.

Missing context / blind spots
  • ⚠️ Runtime validation relies on the author's reported ASan+UBSan experiments with spinning and sleeping workers; this checkout has no local build. Sanitizer builds were still pending at review time, so their subsequent test results remain to be confirmed.
Final Verdict

Status: ✅ Approve. No review changes required.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 15, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 15, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit a72cb3a Oct 16, 2026
352 of 353 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
raimannma added a commit to raimannma/ClickHouse that referenced this pull request Oct 16, 2026
…ryResolveAddress`

ClickHouse#126039 made `StackTrace::tryResolveAddress` return
`ResolvedAddress` instead of `std::optional<ResolvedAddress>`, while
ClickHouse#126137 started using it as an optional in
`gtest_functions_stress.cpp`, so master does not compile `unit_tests_dbms`.

The same change as ClickHouse#126269, to unblock CI here.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126134&sha=latest&name_0=PR&name_1=Build%20(arm_tidy%2C%203%2F4)
PR: ClickHouse#126134
@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-ci 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