Skip to content

Use an 8 MiB stack for the suggestion-loading thread on Darwin - #129026

Merged
Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:suggest-loading-thread-stack-darwin
Nov 3, 2026
Merged

Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:suggest-loading-thread-stack-darwin

Conversation

@groeneai

@groeneai groeneai commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #88234
Related: #107033

Changelog category (leave one):

  • Improvement

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

clickhouse-local and clickhouse-client on macOS now load command-line suggestions in a thread with an 8 MiB stack, like their thread-pool threads, so the suggestion query of an interactive clickhouse-local can no longer overflow the 512 KiB default thread stack during JIT compilation.

Description

Requested in #88234 (comment). Fast test (arm_darwin) failed 05024_local_listener_survives_handler_exception (return code: 56) and 04892_client_dialect_command (spawn id exp6 not open) in 4 PRs in the last 10 days (1, 2, 3, 4). Both are the same event: the clickhouse-local under test dies with EXC_BAD_ACCESS "Thread stack size exceeded" in thread Suggest. All 26 macOS crash reports show: Suggest::fetch -> LocalConnection::sendQuery -> planner -> extractAll -> getRegexpJITMatcher -> LLVM AArch64AsmPrinter.

For LocalConnection the suggestion query is analyzed and planned in Suggest::loading_thread, a plain std::thread, which macOS gives 512 KiB, and LLVM codegen does not call checkStackSize. #107033 gave the global pool and the server pools DEFAULT_THREAD_STACK_SIZE through ThreadWithStackSize; this thread was missed. It now uses ThreadWithStackSize on Darwin; other platforms are unchanged.

Validation on Linux, where ulimit -s sets the default thread stack: the loader fails with TOO_DEEP_RECURSION at 296 KiB and loads at 312 KiB; the main thread runs at 256 KiB. A -DOS_DARWIN build of the same member shape gets an 8 MiB stack even under ulimit -s 512. 05024 and 04892 passed 50/50. No test is added: the crash is Darwin-only and frame-size dependent; the existing interactive darwin tests cover it.


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

Version info

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

groeneai and others added 2 commits November 3, 2026 14:37
For `LocalConnection` (interactive `clickhouse-local`) the whole suggestion
query runs in-process in `Suggest::loading_thread`: analyzer, planner, and the
regexp JIT that `extractAll(word, '[\\w_]{2,}')` triggers during header
evaluation. The thread was a plain `std::thread`, which macOS gives a 512 KiB
stack, and LLVM codegen does not cooperate with `checkStackSize`, so it ran
into the guard page (`EXC_BAD_ACCESS "Thread stack size exceeded"` in thread
`Suggest`). This killed the `clickhouse-local` under test in
`Fast test (arm_darwin)` for `05024_local_listener_survives_handler_exception`
(curl rc 56) and `04892_client_dialect_command` (`spawn id not open`) on
PRs ClickHouse#95355, ClickHouse#88234, ClickHouse#117004 and ClickHouse#117636: 26 of 26 macOS crash reports of those
jobs show this stack.

ClickHouse#107033 gave the global thread pool and the server pools
`DEFAULT_THREAD_STACK_SIZE` via `ThreadWithStackSize`, and 3510173 did
the same for the `clickhouse-local` listener pool; the suggestion loader was
missed. Use `ThreadWithStackSize` for it on Darwin; other platforms keep
`std::thread`, whose default stack follows `RLIMIT_STACK`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the original 'Words are fetched asynchronously.' line and state the Darwin stack need in one line.

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

groeneai commented Nov 3, 2026

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 (3 nits, all in the PR description, fixed before publishing).

# Sev Finding Verdict Evidence / action
1 💡 Use Critical Bug Fix instead of Improvement DISAGREE The crash is seen only in PR builds whose frames cross the 512 KiB limit, not in a stable release; #107033 fixed the same class as Improvement.

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

Session id: cron:clickhouse-review-slot-9:20261103-143900

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Partly. No macOS host, so the Darwin crash is shown by 26/26 identical crash reports from the 4 failing jobs. The mechanism repeats every run on Linux: with ulimit -s 296 the suggestion loader fails TOO_DEEP_RECURSION while the main thread runs at 256 KiB.
b Root cause explained? The in-process suggestion query (planner, regexp JIT, LLVM codegen) runs on a plain std::thread, which macOS gives 512 KiB; LLVM does not call checkStackSize, so it reaches the guard page.
c Fix matches root cause? Yes: the thread is created with DEFAULT_THREAD_STACK_SIZE via ThreadWithStackSize, the remedy #107033 applied to the other threads.
d Test intent preserved / new tests added? No test changed or added: Darwin-only and frame-size dependent; the existing interactive darwin tests (05024, 04892, ...) cover it.
e Both directions demonstrated? Linux is unchanged by construction (identical stack sweep before/after). Darwin: a -DOS_DARWIN build of the same member shape gets 8388608 bytes even under ulimit -s 512; Fast test (arm_darwin) on this PR is the final check.
f Fix is general across code paths? Plain std::thread census: only Suggest runs a query in-process. DistributedQueryPlanExecutorLocal threads run only under private-preview make_distributed_plan and were never observed crashing; different subsystem, not changed.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A: no data path change; covers both clickhouse-local and clickhouse-client loaders.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, protocol or format change; non-Darwin platforms unchanged.
i Invariants and contracts preserved? ThreadWithStackSize mirrors std::thread (join/joinable/move-assign/destructor/ctor errors); the loader uses no thread-exit notifications, the only libc++ bookkeeping it omits.

Session id: cron:clickhouse-impl-slot-41:20261103-141400

@groeneai

groeneai commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @azat @Algunenano, could you review this and add the can be tested label so CI runs? In clickhouse-local the suggestion query runs on Suggest::loading_thread, a plain std::thread with the 512 KiB macOS default, and its regexp JIT codegen overflows that stack (the Fast test (arm_darwin) failures of 05024 and 04892); the thread now uses ThreadWithStackSize on Darwin, like the pools from #107033.

@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1f98695]

Summary: ✅


AI Review

Summary

The PR gives the Darwin suggestion-loading thread an 8 MiB stack through ThreadWithStackSize, preventing the reported stack overflow during in-process suggestion queries. No actionable findings in the changes at 1f98695dca963760b290d55d80a1e790447545b3.

Missing context / blind spots
  • ⚠️ Native macOS execution was not independently reproduced. The available Darwin CI report contains zero test results; a completed run of the existing interactive tests would close this runtime-validation gap. The PR documents the original failures and a stack-size probe.
Final Verdict

Status: ✅ Approve. No code changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 3, 2026
@groeneai groeneai mentioned this pull request Nov 3, 2026
1 task done
@Algunenano Algunenano self-assigned this Nov 3, 2026
@Algunenano Algunenano added the can be tested Allows running workflows for external contributors label Nov 3, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-cli clickhouse-client (interactive CLI) and client library. label Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1f98695dc with master 5087d8155 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 1b0950a13; 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

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

Job report

@Algunenano
Algunenano added this pull request to the merge queue Nov 3, 2026
Merged via the queue into ClickHouse:master with commit 460888d Nov 3, 2026
366 of 367 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 3, 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-cli clickhouse-client (interactive CLI) and client library. pr-improvement Pull request with some product improvements 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