Skip to content

darwin fast test: install lldb on demand via brew on macOS only - #112058

Closed
leshikus wants to merge 6 commits into
ClickHouse:masterfrom
leshikus:lldb-install-on-demand-brew
Closed

leshikus wants to merge 6 commits into
ClickHouse:masterfrom
leshikus:lldb-install-on-demand-brew

Conversation

@leshikus

@leshikus leshikus commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

_ensure_lldb_installed in tests/clickhouse-test puts lldb on PATH so print_c_stacktraces can attach to the server and dump C++ backtraces on a timeout or the end-of-run hung check. The Darwin fast test runs on a bare macOS host (not a container), where lldb is not guaranteed to be on the default PATH.

The previous Linux branch used apt-get, which cannot work in the fast test: that job runs unprivileged in the clickhouse/fasttest container (docker run --user $(id -u):$(id -g), see ci/praktika/runner.py), so apt-get update fails with a permission error and lldb never lands — no c_stacktraces.log is written or attached.

Change

Scope the on-demand install to macOS only. On macOS lldb is installed via Homebrew (brew install llvm), matching how the runner already provisions it; because brew install llvm is keg-only and does not symlink lldb system-wide, the formula's opt/llvm/bin directory is prepended to PATH so shutil.which("lldb") in get_stacktraces_from_lldb resolves the binary. On Linux the helper is a no-op — lldb is baked into the CI images (clickhouse/fasttest, clickhouse/test-base) instead, which landed in #104815. So this is not an "install on every platform" change: macOS installs on demand, Linux relies on the image.

Verified on a real macOS runner: the Darwin fast test produced a symbolicated C++ backtrace via lldb and wrote c_stacktraces.log.

Related: #107173
Related: #104815

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):

`_ensure_lldb_installed` installs `lldb` at runtime so `print_c_stacktraces`
can attach and dump C++ backtraces. On Linux it used `apt-get`, which requires
root; the fast-test container runs unprivileged, so `apt-get update` fails with
"List directory /var/lib/apt/lists/partial is missing. - Acquire (13:
Permission denied)", lldb never lands, and `print_c_stacktraces` only logs
`lldb: command not found` (no c_stacktraces.log is written or attached).

Observed on a testing PR that leaves a query hung until the end-of-run hung
check: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111213&sha=84b4363107f7eb2319eacaafa3e1adb18bae0e36&name_0=PR&name_1=Fast%20test
(PR ClickHouse#111213). There `sql_stacktraces.log`
was attached but `c_stacktraces.log` was missing for the reason above.

Unify the on-demand install on Homebrew, which needs no root and matches how
the macOS runner already provisions lldb (`brew install ... llvm` plus
`{prefix}/opt/llvm/bin` on the job PATH in runner-init.py). `brew install llvm`
is keg-only and does not symlink `lldb` system-wide, so also prepend the
formula bin dir to PATH so `shutil.which("lldb")` resolves the freshly
installed binary.

Related: ClickHouse#107173

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@leshikus leshikus added the can be tested Allows running workflows for external contributors label Jul 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fdf1087]


AI Review

Summary

This PR narrows _ensure_lldb_installed to macOS and fixes the final Linux contract by relying on the current CI images instead of trying to install lldb at runtime in unprivileged containers. I did not find a remaining correctness issue in the current code, but the PR still lacks focused regression coverage for the new Darwin-vs-Linux control flow, so the exact failure mode it addresses would only be caught again on a real timed-out macOS run.

Tests
  • ⚠️ tests/clickhouse-test:1082 Add a small unit test in ci/tests/test_print_stacktraces.py that monkeypatches platform.system, platform.machine, shutil.which, and subprocess.run to prove two behaviors: Darwin prepends opt/llvm/bin and skips brew install when that makes lldb discoverable, and Linux returns without shelling out. The current live-server tests do not exercise _ensure_lldb_installed directly.
Final Verdict

Changes requested: add focused automated coverage for the new _ensure_lldb_installed contract.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 27, 2026
leshikus added a commit to leshikus/ClickHouse that referenced this pull request Jul 27, 2026
… log attachment

Throwaway testing change (do NOT merge) on top of the brew-based lldb install
fix (ClickHouse#112058). Adds a stateless
test that never finishes: it detaches a long-running server-side query (with
max_execution_time = 0 so the server does not self-kill it) into its own
session via os.setsid, so it lingers in system.processes past the end of the
run and the end-of-run hung check dumps and attaches the full server
stacktraces (sql_stacktraces.log / c_stacktraces.log). Its foreground also
hangs past --timeout so it is reported as a timeout.

Related: ClickHouse#107173
Related: ClickHouse#112058

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/clickhouse-test Resolved
`_ensure_lldb_installed` had unified the on-demand install on Homebrew,
but `brew` is not present in the Linux `clickhouse-test` containers, so
that path failed with `ENOENT` on exactly the jobs it was meant to fix.

Use the native package manager per platform: `brew install llvm` on
macOS (keeping the keg-only PATH fix so `shutil.which("lldb")` resolves
the freshly installed binary), `apt-get install -y lldb` on Linux.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/clickhouse-test Resolved
`_ensure_lldb_installed` split the install across two package managers:
Homebrew on macOS and `apt-get` on Linux. The Linux branch can never
work where it matters: the Fast test job runs in the unprivileged
`clickhouse/fasttest` container (`docker run --user $(id -u):$(id -g)`,
see `ci/praktika/runner.py`), so `apt-get install lldb` fails with a
permission error and `c_stacktraces.log` is never written. Installing
`lldb` on Linux belongs in the image, not at runtime -- see PR ClickHouse#104815
(`Install lldb in CI Docker images alongside gdb`).

Drop the dead Linux branch and keep only the macOS Homebrew path (the
Darwin runner is a bare host, not a container, so an on-the-fly install
is the right tool there). On Linux the helper is now a no-op.

Related: ClickHouse#104815
Comment thread tests/clickhouse-test Resolved
…call

`_ensure_lldb_installed` made two `brew` calls: `brew install llvm` and
`brew --prefix llvm` to locate the keg-only `lldb`. The second call is
redundant: `llvm` is keg-only, so its bin dir is the version-stable
`opt/llvm` path under the Homebrew prefix
(`/opt/homebrew` on Apple Silicon, `/usr/local` on Intel). `runner-init.py`'s
`macos_job_path` already hardcodes exactly this path when assembling the
job PATH, so derive it the same way and drop the extra subprocess (and its
failure branch).
@leshikus

Copy link
Copy Markdown
Collaborator Author

The fix succcessfully makes [c_stacktraces.log](https://s3.amazonaws.com/clickhouse-test-reports/PRs/111213/3b38486c9f7e75b91fdeab964032874cb34e8120/fast_test_arm_darwin/c_stacktraces.log), see https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111213&sha=3b38486c9f7e75b91fdeab964032874cb34e8120&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29

@leshikus
leshikus marked this pull request as ready for review July 28, 2026 09:45
@leshikus
leshikus requested a review from Algunenano July 28, 2026 09:46
@Algunenano Algunenano self-assigned this Jul 28, 2026

@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.

The PR description is confusing. The code is only installing it on Darwin, but the PR says Install lldb on demand via Homebrew on every platform instead of apt-get on Linux.

Also, the AI reviewer seems right saying that lldb isn't installed in the Linux fast test image, so it will fail there. Can we add it? We are already installing clang, lld and so on

@leshikus

Copy link
Copy Markdown
Collaborator Author

@Algunenano there is a separate PR regarding installing lldb on Linux, I've just merged it. I'll take a look if the same test provides logs on Linux correctly.

@leshikus leshikus changed the title Install lldb on demand via brew instead of apt-get darwin fast test: install lldb on demand via brew on macOS only Aug 5, 2026
@leshikus

leshikus commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

@Algunenano addressed both points:

  1. Description was misleading — updated. The install is macOS-only; on Linux the helper is a no-op. macOS installs lldb on demand via brew, Linux relies on it being in the image.

  2. lldb in the Linux fast test image — done in Install lldb in CI Docker images alongside gdb #104815 (now merged), which adds lldb-${LLVM_VERSION} to the clang/llvm apt block of clickhouse/fasttest and clickhouse/test-base. Merged master into this branch, so Linux now gets lldb from the image and the previous unprivileged apt-get failure is gone.

Comment thread tests/clickhouse-test Resolved
Review feedback on `_ensure_lldb_installed`:

> here we unconditionally do a `brew install llvm` with a 600-second ceiling before trying the deterministic Homebrew `opt/llvm/bin` path. On the Darwin runners `runner-init.py` already provisions `llvm`, so the common failure mode is "installed but not on `PATH`" [...] Please prepend the known keg-only path and re-check `shutil.which("lldb")` first, then fall back to `brew install llvm` only if it is still absent.

The helper is reached only from the timeout / hung-check cleanup path, so a
networked `brew install` there delays `stop_tests`. `llvm` is already
provisioned on the runner but keg-only, so `lldb` is present yet not on
`PATH`. Prepend the stable `opt/llvm/bin` dir and re-check `shutil.which`
before attempting the install; `brew install llvm` now runs only as a
genuine package-missing fallback. This also fixes an offline case: the old
order returned without prepending the path when `brew` failed, so an
already-present `lldb` was never found.
Comment thread tests/clickhouse-test
attempt already failed.
"""
global _LLDB_INSTALL_ATTEMPTED
if platform.system() != "Darwin":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes _ensure_lldb_installed's contract in two subtle ways that are easy to regress but still unproven by automation: Linux must short-circuit before any shell-out, and Darwin must re-check the deterministic Homebrew opt/llvm/bin path before falling back to brew install.

The existing ci/tests/test_print_stacktraces.py coverage exercises the live-server collectors, but it never stubs _ensure_lldb_installed, so a future reordering or removal of either branch would only be caught again on a real timed-out macOS run. Please add a small unit test that monkeypatches platform.system, platform.machine, shutil.which, and subprocess.run to assert both behaviors.

@leshikus

leshikus commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

A followup PR is created with alternate solution

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 pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants