Skip to content

darwin fast test: attach full server stacktrace dumps as logs; fix lldb attach on macOS - #107173

Merged
leshikus merged 7 commits into
ClickHouse:masterfrom
leshikus:darwin-test-diagnostics
Jul 27, 2026
Merged

leshikus merged 7 commits into
ClickHouse:masterfrom
leshikus:darwin-test-diagnostics

Conversation

@leshikus

@leshikus leshikus commented Jun 11, 2026 •

Copy link
Copy Markdown
Collaborator

When a clickhouse-test test times out — or the end-of-run hung check fires — the runner dumps server stacktraces. On the macOS Fast test (arm_darwin) run this surfaced two reporting problems:

  • The full system.stack_trace dump (over a thousand threads) and the lldb backtraces were inlined into the test description, flooding job.log (~31k lines for a single timeout) and the per-test report info (capped at 16384 bytes, so it was also truncated there).
  • lldb --batch -p <pid> could not attach on the macOS runner and exited 1, and shell_get_output discarded the command output, so the log kept only returned non-zero exit status 1 without the reason.

This PR:

  • Writes the full dumps to per-collector files (sql_stacktraces.log, c_stacktraces.log) and attaches them to the report from fast_test.py; stdout keeps only a trim_for_log preview. The files are per collector, not per test, because the hung check has no single owning test.
  • Attaches lldb as root on Darwin (the runner grants passwordless sudo and root holds task_for_pid rights); shutil.which resolves the path because sudo resets PATH. Linux is unchanged.
  • Surfaces the merged stdout/stderr of a failed command in shell_get_output so the real failure reason is logged, bounded with trim_for_log so a command that prints many lines and only then exits non-zero (e.g. lldb dumping backtraces) cannot flood job.log.
  • Orders the system.stack_trace dump query_id <> '' DESC, thread_id DESC so the wedged query's threads (and newest threads) come first.
  • Bounds the inline timeout/cleanup diagnostic with trim_for_log.

The Darwin skip-list changes and the macOS no-JIT override are split out into separate pull requests.

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.8.1.199 (included in 26.8 and later)

@leshikus leshikus added the can be tested Allows running workflows for external contributors label Jun 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f5dbada]

Summary: ✅


AI Review

Summary

This PR moves clickhouse-test timeout and hung-check stacktraces out of inline output, trims the job.log preview, and teaches fast_test.py to upload the full dumps as artifacts. The stacktrace capture changes themselves look reasonable, but the rollout is incomplete: only fast_test.py publishes the new side files, while other clickhouse-test jobs still take the trimmed-preview path and lose the full dump.

Findings

⚠️ Majors

  • [tests/clickhouse-test:1169-1170] clickhouse-test now writes the full server dumps into relative side files and keeps only a 100-line preview in stdout, but only ci/jobs/fast_test.py uploads those files. The main functional-test command at ci/jobs/functional_tests.py:125 and the diagnostics replay at ci/jobs/functional_tests.py:1215 still run clickhouse-test --hung-check --capture-client-stacktrace without changing into ci/tmp, and their artifact path is still just CH.prepare_logs. On those jobs the full sql_stacktraces.log / c_stacktraces.log never reaches the report, so this PR regresses the common clickhouse-test callers from “full dump inline” to “100-line preview only”. Suggested fix: thread an explicit stacktrace-output directory into clickhouse-test and publish those files from the shared log-collection path instead of wiring only fast_test.py.
Final Verdict

⚠️ Changes requested: the full-dump artifact path needs to be implemented for the shared clickhouse-test callers, not just fast_test.py.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 11, 2026
Comment thread tests/clickhouse-test Resolved
… fix lldb on macOS

On a per-test timeout or the end-of-run hung check, `clickhouse-test` dumps
server stacktraces. Two problems showed up in the macOS fast test:

- The full `system.stack_trace` dump (over a thousand threads) and the lldb
  backtraces were inlined into the test description, flooding `job.log` (~31k
  lines for a single timeout) and the per-test report `info`.
- `lldb --batch -p <pid>` failed to attach on the macOS runner and `exit 1`,
  and `shell_get_output` discarded the command output, so the log kept only
  `returned non-zero exit status 1` without the reason.

Changes:

- Write the full dumps to per-collector files (`sql_stacktraces.log`,
  `c_stacktraces.log`) and attach them to the report from `fast_test.py`;
  stdout keeps only a `trim_for_log` preview. The files are per collector, not
  per test, because the hung check has no single owning test.
- Attach lldb as root on Darwin (the runner has passwordless sudo and root
  holds `task_for_pid` rights); `shutil.which` resolves the path since sudo
  resets `PATH`. Linux is unchanged.
- Surface the merged stdout/stderr of a failed command in `shell_get_output`,
  bounded with `trim_for_log` so a command that prints many lines and only
  then exits non-zero (e.g. lldb dumping backtraces) cannot flood `job.log`.
- Order the `system.stack_trace` dump `query_id <> '' DESC, thread_id DESC`
  so the wedged query's threads (and newest threads) come first.
- Bound the inline timeout/cleanup diagnostic with `trim_for_log`.
@leshikus
leshikus force-pushed the darwin-test-diagnostics branch from a805117 to 53e9d06 Compare June 12, 2026 12:58
leshikus added 2 commits June 12, 2026 15:52
… trim_for_log

Address review feedback on the stacktrace reporting:

- shell_get_output gains keep_output_on_error: lldb may exit non-zero yet
  still print backtraces (or an attach error) worth keeping. With the flag the
  caller receives that output, so print_c_stacktraces saves the full dump to
  c_stacktraces.log and prints only a trim_for_log preview — the same path as
  a successful run — instead of shell_get_output dumping it to stderr with
  nothing attached. The default path is unchanged for the other callers.
- trim_for_log now newline-terminates its result, so callers no longer each
  re-add the trailing newline that splitlines() drops.
…ir as Path

- The stdout previews kept trim_for_log's default 10000-line limit, so a ~31k
  line dump still put 10000 lines in job.log. Now that the full dump is
  attached as a file, pass an explicit 100-line limit (the small-preview limit
  already used elsewhere in this file) to print_c_stacktraces,
  print_sql_stacktraces and the timeout/cleanup diagnostic. With the reordered
  dump (query_id <> '' DESC) the wedged-query threads lead the preview.
- fast_test.py: temp_dir becomes a Path, so f"{temp_dir}/..." no longer
  produces double slashes and the stacktrace-log paths join with the / operator.
- clickhouse-test: the per-collector log comment claimed appends cannot corrupt
  across two simultaneous --jobs timeouts. O_APPEND only keeps a single write()
  atomic and a large dump can span several writes, so two workers may
  interleave; reword to say the per-block headers keep the result readable.
@leshikus
leshikus marked this pull request as ready for review June 12, 2026 14:32
@leshikus
leshikus requested a review from maxknv June 12, 2026 14:32
@leshikus

Copy link
Copy Markdown
Collaborator Author

@tavplubix we have a discussion if lldb is still needed if we have .ips files in the report, please let me know what do you think if lldb stack traces should be enabled

@tavplubix

Copy link
Copy Markdown
Member

We still need lldb collect stacktraces on linux. We could just save a coredump instead, but we still need to show stacktraces in a human-readable format

Comment thread tests/clickhouse-test Resolved
…g comments

tavplubix pointed out that ordering server stacktraces newest-first via
thread_id DESC does not make sense: thread_id is not monotonic (TIDs are
reused after a thread exits) and GlobalThreadPool reuses threads, so the
highest TID is not the last thread. Idle threads are also not always
noise — a query may be waiting on a background operation.

Drop the thread_id DESC part and keep only query_id <> '' DESC, which
surfaces threads currently executing a query at the top of the trimmed
stdout preview on a timeout. All other threads still follow and the full
dump is attached as a log file, so nothing is dropped. Rewrite the
comments to drop the refuted claims.

Related: ClickHouse#107173
Comment thread tests/clickhouse-test Resolved
Revert the ORDER BY reordering of the server-stacktrace SQL queries so they
match master exactly: query_id-first ordering only affected the trimmed
stdout preview, and the full dump is attached as a log regardless, so it is
not worth diverging from master. tavplubix also objected to the reasoning.

The three queries are back to their pre-PR form:
- replicated / shared catalog: ORDER BY host, thread_id
- single node: no ORDER BY

Related: ClickHouse#107173
The client-stacktrace path in the timeout kill handler printed the raw
output of `get_stacktraces_from_lldb` directly. Because that helper is
called with `keep_output_on_error=True`, it returns the full lldb output
even on a non-zero exit (e.g. a later `detach`/`quit` fails after many
frames were already printed), so the whole payload went straight into
`job.log` unbounded. Wrap it in `trim_for_log`, matching the bounded
error path in `shell_get_output`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread tests/clickhouse-test Resolved
Comment thread tests/clickhouse-test
# trimmed preview. Append with a per-block header so successive dumps stay
# separated; two --jobs workers timing out at once may still interleave (a
# large write is not atomic), but the headers keep the result readable.
SQL_STACKTRACES_LOG = "sql_stacktraces.log"

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.

clickhouse-test is a shared runner, but this new side-file path is only wired into fast_test.py. The main functional-test command at ci/jobs/functional_tests.py:125 and the diagnostics replay at ci/jobs/functional_tests.py:1215 still run clickhouse-test --hung-check --capture-client-stacktrace and only collect artifacts through CH.prepare_logs().

Because SQL_STACKTRACES_LOG / C_STACKTRACES_LOG are just relative filenames, those jobs keep only the new 100-line stdout preview; the full sql_stacktraces.log / c_stacktraces.log never reaches the report there. In functional_tests.py they do not even cd into ci/tmp, so the files are written wherever the job cwd happens to be.

Please either thread an explicit stacktrace-output directory through clickhouse-test and teach the shared log collector to upload these files, or update every clickhouse-test caller before trimming the common timeout diagnostics globally.

leshikus added a commit to leshikus/ClickHouse that referenced this pull request Jul 24, 2026
…ives to the hung check

The first run (https://github.com/ClickHouse/ClickHouse/actions/runs/29824157352)
showed the detached SELECT was aborted by the server before the end-of-run hung
check could see it: with the fast-test profile default max_execution_time=600,
the speed estimator killed it with "Code: 160 ... Estimated query execution time
(99683 s) is too long. Maximum: 600" at 13:10:33, ~90s before the hung check ran
at 13:12:00. So system.processes was empty, the hung check reported "No queries
hung", and no sql_stacktraces.log / c_stacktraces.log were written or attached.

Add max_execution_time = 0 and max_estimated_execution_time = 0 so the query
never ends and is guaranteed to still be running when the hung check fires.

Related: ClickHouse#107173

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@leshikus

Copy link
Copy Markdown
Collaborator Author

Verified the reporting fix end-to-end with a throwaway testing PR (#111213) that adds an artificial test leaving a query hung until the end-of-run hung check.

Fast test report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=111213&sha=84b4363107f7eb2319eacaafa3e1adb18bae0e36&name_0=PR&name_1=Fast%20test

What it shows:

  • The hung check fired, found the wedged query, and wrote the full system.stack_trace dump (12602 lines) to sql_stacktraces.log, which is attached to the report.
  • job.log kept only a trimmed preview (----12502 lines are hidden---- + (full system.stack_trace dump saved to sql_stacktraces.log)) instead of the ~31k-line flood.

Caveat: this run is the Linux Fast test, so it only exercises the cross-platform SQL-dump-to-file/attach path. c_stacktraces.log was not produced here because the Linux fast-test image has no lldb (lldb: command not found); the sudo lldb attach on Darwin still needs the Fast test (arm_darwin) job to run.

@Algunenano Algunenano self-assigned this Jul 27, 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.

LGTM with some minor comments:

  • Please update the PR description. It has some outdated sentences.
  • Let's add the dump paths for all stateless tests, not just fasttest.

This would be really useful to me to investigate the hungs in #111579. I managed to reproduce and fix the crashes, but not the hangs yet. Having traces would be of great help

Comment thread ci/jobs/fast_test.py
# clickhouse-test runs with cwd=temp_dir, so the full server stacktrace
# dumps it writes on a timeout / hung check land here. Attach them so
# the report links the full dumps (stdout keeps only a trimmed preview).
for stacktrace_log in ("sql_stacktraces.log", "c_stacktraces.log"):

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.

Let's add these to stateless tests too please. Also, it'd be nice if these were global constants instead of hardcoded names. Maybe we can put them in a common place to share them with clickhouse-test (already has them as SQL_STACKTRACES_LOG / C_STACKTRACES_LOG) and functional_test

@leshikus
leshikus added this pull request to the merge queue 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]>
Merged via the queue into ClickHouse:master with commit 7a06812 Jul 27, 2026
177 checks passed
@leshikus
leshikus deleted the darwin-test-diagnostics branch July 27, 2026 10:18
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 27, 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 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.

4 participants