Skip to content

Do not fail the Stress test job when the server stops during the shutdown grace period - #116841

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:stop-server-grace-period-return-success
Aug 28, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:stop-server-grace-period-return-success

Conversation

@groeneai

@groeneai groeneai commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #109225

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

...

Description

stop_server in tests/docker_scripts/stress_tests.lib returns a failing status on the
branch that means the server shut down cleanly, just slowly.

After clickhouse stop --do-not-kill times out it writes Warning: server did not stop yet,
terminates gdb, waits 60 seconds and rechecks the pid:

kill -s 0 "$pid" || return

A bare return propagates the last command's status, here the kill -s 0 that just failed
because the process is gone. So the branch whose own comment reads "the server
could finally stop" returns 1. stress_runner.sh runs under set -e and calls stop_server
bare at line 330, so the script aborts and the job becomes Check failed with exit code 1.

Two costs: the job invents a failure on a run where the server did stop, and the steps below
line 330 never run, so check_logs_for_critical_errors never applies its S3_ERROR No such key thrown and lost-SharedMergeTree detectors.

Over 30 days, among Stress test runs carrying the warning row (grouped per PR, commit and
check): 5 groups / 5 PRs (1 on master) lack a Possible deadlock on shutdown row and failed;
30 groups / 27 PRs (2 on master) have it and passed. Perfectly anti-diagonal: deterministic,
not flaky. upgrade_runner.sh:349 reaches the same line and is fixed with it.

Reference run (arm_debug):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109225&sha=b339930e18c91cefedc528a8370375ce7a2da4e9&name_0=PR&name_1=Stress%20test%20%28arm_debug%29

No test added: this is a docker-only bash function reached through hardcoded absolute paths,
and ci/tests/ is being removed. I validated locally by driving the real function text with
stubbed clickhouse, gdb, pidof and ts in three fixtures (server dies inside the grace
window, outlives it, already gone); reverting the token reddens the first and third, an
unconditional return reddens the second. The remaining detector is CI itself: a Stress test
run carrying the warning row and no Possible deadlock on shutdown must be green.


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

Version info

  • Merged into: 26.9.1.267 (included in 26.9 and later)

…down grace period

stop_server writes "Warning: server did not stop yet" when
`clickhouse stop --do-not-kill` times out, terminates gdb, waits 60 seconds
and then rechecks the pid:

    kill -s 0 "$pid" || return

A bare `return` propagates the last command's status, which on this branch is
the `kill -s 0` that has just failed because the process is gone. So the branch
whose own comment reads "The server could finally stop while we were
terminating gdb" returns 1 exactly when the server did stop. The polarity is
inverted: the good outcome returns failure, while the bad outcome falls through
to `clickhouse stop --force` and returns 0, reporting through the
"Possible deadlock on shutdown" row in test_results.tsv.

stress_runner.sh runs under `set -e` and calls stop_server bare at line 330, so
the non-zero status aborts the script and stress_job.py appends a job-level
"Check failed with exit code 1" row. Two consequences: the check invents a
failure on a run where shutdown completed, and because the abort is at line 330
the steps below it never run, so check_logs_for_critical_errors never applies
its "S3_ERROR No such key thrown" and "Lost forever for SharedMergeTree"
detectors and dmesg.log is not collected.

Measured over 30 days in the CI database, grouped per (pull request, commit,
check) among Stress test runs carrying the warning row: 5 groups over 5 pull
requests (1 on master) have no "Possible deadlock on shutdown" row and failed,
while 30 groups over 27 pull requests (2 on master) have that row and passed.
The table is perfectly anti-diagonal over all 35 groups, so the behaviour is
deterministic rather than flaky. It also states the contract this function is
meant to satisfy: stop_server exits 0 once the server is no longer running, and
shutdown problems travel as test_results.tsv rows rather than as an exit status.

upgrade_runner.sh:349 reaches the same line with check_hang defaulted to true
and is fixed by the same change, with no observed occurrence in 30 days.
upgrade_runner.sh:170 passes check_hang=false and takes the other branch.

Validated by driving the extracted function text with stubbed clickhouse, gdb,
pidof and ts in three fixtures: the server exits inside the grace window, it
outlives the window, and it is already gone before the first check. The pre-fix
text fails the first and third with the caller aborting, the fixed text passes
all three, and replacing the guard with an unconditional `return 0` fails the
second, which is what keeps the deadlock report honest.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings), which read
stress_tests.lib in full, all six callers, the downstream control flow, the sibling shutdown
helper and clickhouse stop.

My own cold review of the resulting tree, done before reading the author's evidence, raised two
items. Neither is in the source; both were resolved before this PR was opened.

# Sev Finding Verdict Evidence / action
1 ⚠️ The provenance link sat inside the template's HTML comment block, so it did not render AGREE, fixed before publication Related: is now a visible line. In the 14 most recently merged pull requests it is outside the comment block in 14 of 14
2 💡 An internal validation note described the pre-fix arm as read from HEAD, which already carries the fix AGREE, fixed before publication The harness reads the pinned base 438a6180ae96 and refuses to run if that ref carries the fix. Wording corrected, no code change

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

Session id: cron:clickhouse-review-slot-9:20260828-081700

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 28, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 28, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One command, no rate: the real stop_server text is driven inside a set -ex driver mirroring stress_runner.sh:330, with stubbed clickhouse, gdb, pidof, ts. Each fixture asserts its own premise before the run. The CI-side evidence is likewise deterministic: the 30-day contingency table is perfectly anti-diagonal over 35 groups.
b Root cause explained? Yes. A bare return yields the last command's status, here the kill -s 0 that failed because the process is gone, so the branch meaning "the server did stop" returns 1. stress_runner.sh is set -e and calls stop_server bare at line 330, so the script aborts and stress_job.py:422-429 renders Check failed with exit code 1.
c Fix matches root cause? Yes. || return 0 gives the early return the explicit success status the surrounding code already assumes. Not a widened bound and not a suppression. Rejected alternatives: stop_server || true at the five call sites, and making the function never fail, both of which would also swallow genuine clickhouse stop --force failures.
d Test intent preserved / new tests added? Preserved. The Possible deadlock on shutdown FAIL path is untouched and is pinned by the fixture where the server outlives the grace window, which is the only fixture that catches an unconditional return 0. No committed test: this is a docker-only bash function reached through hardcoded absolute paths, ci/tests/ is being removed, and a lib-only change is a CI Tests digest cache hit.
e Both directions demonstrated? Yes, same fixture and command. Pre-fix text taken from the pinned base 438a6180ae96, not from HEAD which already carries the fix: exit 1, caller aborted. Fixed text: exit 0, caller continued, with the warning row written and no deadlock row in either case.
f Fix is general across code paths? Yes. stress_tests.lib:307 is the only || return with no explicit status in all non-contrib shell code; every other first-party one carries an explicit status. Both call sites that reach the line (stress_runner.sh 77/227/312/330, upgrade_runner.sh:349) are fixed by it. upgrade_runner.sh:170 passes check_hang=false and is not a carrier. The unrelated stop_server in run-fuzzer.sh and the Python one in clickhouse_proc.py were checked and excluded.
g Fix generalizes across inputs? Yes, and the input space is fully enumerated: the branch's only input is whether the pid is alive at the recheck. Both values are covered, plus both sub-cases of "not alive" (died during the grace window, already gone before it), separated by an asserted arming condition rather than by timing. No datatype axis exists for a shell exit status.
h Backward compatible? Yes, trivially. Harness-only: no setting, no SettingsChangesHistory entry, no serialization format, no user-visible behaviour. The only change is that a job which used to abort now continues into the steps it was skipping.
i Invariants and contracts preserved? Yes. Invariant: stop_server exits 0 once the server is no longer running, and shutdown problems travel as test_results.tsv rows rather than as an exit status, which is what the 30 deadlock runs already do. The deadlock and check_hang=false branches are untouched, so a real clickhouse stop --force failure still propagates. Continuing past a completed shutdown is not a new path: those 30 runs already return 0 and run the same following lines. A failed kill -s 0 means the pid is gone, so the server log is complete before the mv, and lingering ports are already handled by wait_server_port_free.

Session id: cron:clickhouse-impl-slot-40:20260828-075300

@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fca818f]

Summary: ✅


AI Review

Summary

This PR fixes stop_server in tests/docker_scripts/stress_tests.lib so the helper returns success when the server actually exits during the post-timeout grace period instead of propagating the failed kill -s 0 probe. I traced that contract through the stress_runner.sh and upgrade_runner.sh call sites, checked the prior PR discussion and current CI state, and did not find any remaining correctness, safety, or metadata issues.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? stop_server's 60 second shutdown grace period ends in a bare return, which propagates the failed kill -s 0, so the branch meaning "the server did stop" returns 1 and aborts stress_runner.sh under set -e. That failed 5 Stress test runs in 30 days whose server had in fact stopped, and it also skipped the S3 and SharedMergeTree log detectors that run below the call.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - fca818fab10b312a351eefb33d898b640982e211

CI is fully finished on this head, and reading it needs one caveat: the head carries two
174-job PR workflow runs (plus four 2-job side runs), so result_pr.json is last-writer-wins and
currently renders the whole workflow OK with no failing child. That is not the state of the head.
Per-run: 33156531609 is completed/failure with Stress test (amd_msan) red, 33156541237 is
completed/success with the same 174 jobs and no failure. Config Workflow, Style check and
Finish Workflow are success. The one failure has an owner and is not caused by this PR.

Check / test Reason Owner / fixing PR
Stress test (amd_msan) / Logical error: Shard number is greater than shard count: shard_num=2 shard_count=1 cluster=test_cluster_one_shard_three_replicas_localhost (STID 5066-457d) a parallel-replicas shard number is validated against a cluster that did not produce it, aborting at src/Interpreters/ClusterProxy/executeQuery.cpp:788 in prepareClusterForParallelReplicas under executeQueryWithParallelReplicas. Trunk defect, first seen 2026-08-03, 60 CIDB rows over 46 distinct PRs with 8 true-master rows in 30 days, and this PR's entire diff is one shell library, tests/docker_scripts/stress_tests.lib fixing PR #113589 (mine, open)

The owner is exact rather than same-area: #113589 "Bind the parallel replicas shard scope to the
cluster that produced it" rewrites that very function (its diff carries the hunk
@@ -767,16 +850,16 @@ static std::pair<ClusterPtr, size_t> prepareClusterForParallelReplicas),
which is the frame that aborts here.

This head also supplies its own control: two runs executed the identical tree and disagreed on this
leg, failure in one and success in the other, so the red is state or timing dependent rather
than tree dependent. Nothing in a change to the stress harness's shutdown handling can reach a
cluster-scope assertion in the server, and the signature predates this branch by 25 days.

Session id: cron:our-pr-ci-monitor:20260828-100000

@alexey-milovidov alexey-milovidov self-assigned this Aug 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 28, 2026
Merged via the queue into ClickHouse:master with commit ba766af Aug 28, 2026
360 of 362 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 Aug 28, 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 groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect manual approve Manual approve required to run CI 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