Skip to content

CI: collect server stacktraces on server death, simplify stop logic - #104081

Merged
leshikus merged 4 commits into
ClickHouse:masterfrom
leshikus:ci-server-died-stacktraces
May 8, 2026
Merged

leshikus merged 4 commits into
ClickHouse:masterfrom
leshikus:ci-server-died-stacktraces

Conversation

@leshikus

@leshikus leshikus commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

clickhouse-test has a print_stacktraces function that collects gdb/system.stack_trace backtraces, but it was only called at startup and during the hung-query check — never when the server was detected dead mid-run. This left the most important failure mode without any trace output.

Changes

Stacktrace collection on server death — print_stacktraces is now called at the two earliest detection points:

  • When a test result comes back with FailureReason.SERVER_DIED (in run_tests_array)
  • When the liveness hung-check finds the server unresponsive (in do_run_tests)

Removed ServerDied exception — the exception was raised immediately after setting the server_died event, so it was redundant: the event already signals all workers to stop, and main already sets exit code 1 when the event is set. Replaced all raises with break. The two non-server-death stops (--max-failures limit and max failures chain) now print an explicit message before breaking. A bug was also fixed where these two cases did not set the stop flag, so main's suite loop would continue into subsequent suites.

Renamed server_died → stop_testing — the flag is now set for --max-failures and failures-chain limits too, not only for actual server death, so the old name was misleading.

Changelog category (leave one):

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

Version info

  • Merged into: 26.5.1.456

leshikus added 3 commits May 5, 2026 11:13
…tion

Call `print_stacktraces` at the two points where server death is first
detected: when a test result comes back with `FailureReason.SERVER_DIED`,
and when the liveness hung-check finds the server unresponsive.

Replace all `raise ServerDied` with `break` — the `server_died` event
already signals all workers to stop, and `main` already sets exit code 1
when the event is set, so the exception was redundant. Remove the
`ServerDied` class and its top-level handler entirely.

The two non-server-death stops (`--max-failures` limit and max failures
chain) now print an explicit message before breaking instead of relying
on the exception message.
…_chain

Without this, breaking out of run_tests_array for these two cases
left server_died unset, so main's suite loop would continue running
subsequent test suites instead of stopping.
The flag is set not only when the server dies but also when
--max-failures or the failures chain limit is reached.
`stop_testing` better describes its role as a general
"stop all test execution" signal.
@clickhouse-gh

clickhouse-gh Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [326fd24]

Summary: ✅


AI Review

Summary

This PR updates tests/clickhouse-test to collect server stack traces at the earliest server-death detection points and refactors stop signaling through stop_testing. The change is coherent with the stated CI reliability goal, and I did not find correctness, safety, or rollout issues that require code changes.

Missing context
  • ⚠️ No CI run logs or test artifacts were available in this review context.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 5, 2026
@leshikus
leshikus requested a review from maxknv May 5, 2026 09:26
@leshikus
leshikus marked this pull request as ready for review May 5, 2026 09:26
@maxknv

maxknv commented May 5, 2026

Copy link
Copy Markdown
Member

IMHO, it's more error-prone to replace exception with break. We can break just the nested loop. Also, we still have GlobalTimeout exception and bare raises. The approach now is mixed. I'd prefer a separate exception for each reason, with distinct exit codes.

@leshikus

leshikus commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

@maxknv the problem with the exception is a broken metaphor; we generally should be able to throw it everywhere; this is not the case for multi-process code, we have to stop other processes before throwing the exception; please let me know if I should restore exception

Bring back the `ServerDied` exception class, the four `raise ServerDied`
call sites in `run_tests_array`, and the top-level `except ServerDied`
handler, reverting the control-flow part of the earlier refactor.

The `stop_testing` rename and the `print_stacktraces` calls at the two
server-death detection points (test result with `SERVER_DIED` reason and
hung-check liveness failure) are kept. The `stop_testing.set` calls at
the `--max-failures` and `max_failures_chain` sites are also kept so the
main suite loop still observes the stop signal across processes.
@leshikus
leshikus added this pull request to the merge queue May 8, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 8, 2026
@leshikus
leshikus added this pull request to the merge queue May 8, 2026
Merged via the queue into ClickHouse:master with commit 25f9511 May 8, 2026
165 checks passed
@leshikus
leshikus deleted the ci-server-died-stacktraces branch May 8, 2026 17:29
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 8, 2026
pull Bot pushed a commit to sonvt1710/ClickHouse that referenced this pull request May 19, 2026
ClickHouse#104081 renamed the `server_died` event to `stop_testing` in
`clickhouse-test` and replaced the parent-side print
`Server died, terminating all processes...` with
`Stopping tests, terminating all processes...`. The functional-tests
results parser still searched for the old string, so when a Bugfix
validation run actually killed the server it failed to emit the
synthetic `Server died` leaf that the inversion step in
`ci/jobs/functional_tests.py` flips to OK — and the job reported
`Failed to reproduce the bug` even though the bug had reproduced.

Realign the two SIGN constants to the wording the runner now emits
and rename the carried variable/field to `stop_testing` to match.

Observed on the `Bugfix validation (functional tests)` job of
ClickHouse#105286
(server crashed under the test, log: `Stopping tests, terminating all processes...`).

Refs ClickHouse#104081
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request May 20, 2026
Follow-up to PR ClickHouse#105298 (ClickHouse#105298 (comment))
and PR ClickHouse#104081 (ClickHouse#104081).

Previously the job-side parser detected the stop_testing condition (server
died, hung check failed, --max-failures reached, etc.) by matching specific
strings in `test_result.txt`. Every wording change in `clickhouse-test`
risked silently breaking bugfix validation - exactly what happened when
PR ClickHouse#104081 renamed `Server died, terminating all processes...` to
`Stopping tests, terminating all processes...`.

Replace that fragile log-line matching with a stable contract: an exit
code. `clickhouse-test` now exits with `STOP_TESTING_EXIT_CODE = 2` when
the run is aborted via a new `StopTesting` exception (renamed from
`TestRunAbort`, mirroring `StopIteration`). All paths that previously set
the `stop_testing` event now raise `StopTesting` and unwind to a single
outer handler that exits with the new code - including the parent-side
hung-check path (which used to `break` after killing workers) and the
`create_common_database` failure path (which used to re-raise the original
exception, bypassing the handler entirely).

The job-side parser (`functional_tests_results.py`) treats
`runner_exit_code == STOP_TESTING_EXIT_CODE` as the authoritative
stop_testing signal - no more `STOP_TESTING_SIGN` / `STOP_TESTING_SIGN2`
matching. The constant itself is read straight from `tests/clickhouse-test`
via `runpy.run_path`, so there is a single source of truth.

`ClickHouseProc.run_test` (used by `fast_test.py`) now returns the integer
exit code instead of a bool so this signal reaches the parser for the
fast-test invocation too.

Behavioural change worth noting: when `StopTesting` unwinds from
`do_run_tests` in the parent-side hung-check path, the end-of-main cleanup
steps (final hung check, restarted-tests printing, coverage flush, trace
log analysis) are skipped. This is acceptable since the server is
unresponsive in that path anyway; the diagnostics would fail.

### Changelog category (leave one):
- CI Fix or Improvement (changelog entry is not required)

### Changelog entry:
...
DavidHe-2008 pushed a commit to DavidHe-2008/ClickHouse that referenced this pull request Jun 1, 2026
Follow-up to PR ClickHouse#105298 (ClickHouse#105298 (comment))
and PR ClickHouse#104081 (ClickHouse#104081).

Previously the job-side parser detected the stop_testing condition (server
died, hung check failed, --max-failures reached, etc.) by matching specific
strings in `test_result.txt`. Every wording change in `clickhouse-test`
risked silently breaking bugfix validation - exactly what happened when
PR ClickHouse#104081 renamed `Server died, terminating all processes...` to
`Stopping tests, terminating all processes...`.

Replace that fragile log-line matching with a stable contract: an exit
code. `clickhouse-test` now exits with `STOP_TESTING_EXIT_CODE = 2` when
the run is aborted via a new `StopTesting` exception (renamed from
`TestRunAbort`, mirroring `StopIteration`). All paths that previously set
the `stop_testing` event now raise `StopTesting` and unwind to a single
outer handler that exits with the new code - including the parent-side
hung-check path (which used to `break` after killing workers) and the
`create_common_database` failure path (which used to re-raise the original
exception, bypassing the handler entirely).

The job-side parser (`functional_tests_results.py`) treats
`runner_exit_code == STOP_TESTING_EXIT_CODE` as the authoritative
stop_testing signal - no more `STOP_TESTING_SIGN` / `STOP_TESTING_SIGN2`
matching. The constant itself is read straight from `tests/clickhouse-test`
via `runpy.run_path`, so there is a single source of truth.

`ClickHouseProc.run_test` (used by `fast_test.py`) now returns the integer
exit code instead of a bool so this signal reaches the parser for the
fast-test invocation too.

Behavioural change worth noting: when `StopTesting` unwinds from
`do_run_tests` in the parent-side hung-check path, the end-of-main cleanup
steps (final hung check, restarted-tests printing, coverage flush, trace
log analysis) are skipped. This is acceptable since the server is
unresponsive in that path anyway; the diagnostics would fail.

### Changelog category (leave one):
- CI Fix or Improvement (changelog entry is not required)

### Changelog entry:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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