Skip to content

Extend Run server init.d retry budget from 5s to 30s - #106056

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-initd-test-retry-86278
May 29, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-initd-test-retry-86278

Conversation

@groeneai

@groeneai groeneai commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

The Run server init.d test in the Install packages (amd_release) job has been failing intermittently on master with the same pattern across 3 different ClickHouse versions in the last 30 days:

Date Commit Version
2026-05-11 08:30 66ce9a35d04f 26.5.1.507
2026-05-22 11:27 94976df6f78a 26.6.1.88
2026-05-28 13:34 549ac9afd4ee 26.6.1.216

All three runs end with the same tail:

+ SYSTEMCTL_SKIP_REDIRECT=1 /etc/init.d/clickhouse-server start
Waiting for server to start
Waiting for server to start
Server started
+ for i in {1..5}
+ clickhouse-client -q 'SELECT version()'
Code: 210. DB::NetException: Connection refused (localhost:9000). (NETWORK_ERROR)
...
(repeats 5x with sleep 1, then a final unconditional clickhouse-client also fails)
+ exit 1

Root cause

The initd_test script in ci/jobs/install_check.py polls clickhouse-client -q 'SELECT version()' only 5 times with sleep 1 between attempts after the init.d wrapper returns. The wrapper prints Server started once the pid file exists, but the TCP listener on port 9000 can take longer than 5 seconds to bind on a slow CI host.

The preserved clickhouse-server.log from the 2026-05-28 hit confirms this: the server process forked at 13:35:50.269225, and preserve_logs.sh (the trap ... ERR handler) copied the log at 13:35:50.586761 — only ~317 ms after fork. The server had not yet reached the listener-open stage by the time the test gave up.

The sibling keeper_test block in the same file already uses a 20-iteration loop with a /dev/tcp probe for the same purpose. This PR aligns initd_test with that pattern by bumping the retry budget from 5 to 30 iterations. Passing runs still complete on the first iteration because the loop breaks on the first successful client call.

Related

CI Reports

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

The `initd_test` script in `ci/jobs/install_check.py` retries
`clickhouse-client -q 'SELECT version()'` 5 times with `sleep 1` between
attempts after the init.d wrapper returns "Server started". On slow CI
hosts the server takes longer than 5 seconds to open the TCP listener
after the wrapper has printed "Server started" (which only checks that
the pid file exists). The test then fails with
`Code: 210. DB::NetException: Connection refused (localhost:9000)`.

CIDB shows 3 master hits in 30 days with identical failure mode across
3 versions (26.5.1.507, 26.6.1.88, 26.6.1.216). For the most recent
hit, the preserved `clickhouse-server.log` shows the server process
forked at `13:35:50.269225` and the `preserve_logs.sh` trap copied the
log at `13:35:50.586761`, only ~317 ms after fork: the server had not
yet reached the listener-open stage by the time the test gave up.

The sibling `keeper_test` block in the same file already uses a
20-iteration loop with `/dev/tcp` for the same purpose. Bumping
`initd_test` to 30 iterations brings the budget in line and removes
the spurious failures; passing runs still complete on the first
iteration because the loop breaks early.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=549ac9afd4ee4fd58d177ad5b7b88b4a517805d6&name_0=MasterCI&name_1=Install%20packages%20%28amd_release%29
Related: ClickHouse#86278
@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

a. Deterministic repro? Not locally (this is a Docker-based packaging test against a pre-built .deb), but the failure is mechanically isolated by direct evidence: 3 identical 30-day master hits + the preserved server log showing the server process was still in its first ~317 ms when preserve_logs.sh copied it.

b. Root cause? /etc/init.d/clickhouse-server start prints Server started once the pid file exists. The clickhouse-server.log for the 2026-05-28 hit shows the server forked at 13:35:50.269225 and preserve_logs.sh copied the log file at 13:35:50.586761 (~317 ms later). The TCP listener on port 9000 had not yet been bound by the time the test exhausted its 5 retries.

c. Fix matches root cause? Yes. The fix extends the retry budget that previously timed out. It does not weaken any assertion: the final unconditional clickhouse-client -q 'SELECT version()' is preserved, and the subsequent grep against /proc/<pid>/environ (which is the actual test invariant) is unchanged.

d. Test intent preserved? Yes. The test still asserts (i) init.d-started server is reachable via clickhouse-client, and (ii) TEST_THE_DEFAULT_PARAMETER propagates through /etc/default/clickhouse to the server process's environ. Both invariants are unchanged. The 30-iteration loop matches the existing keeper_test pattern in the same file.

e. Demonstrated in both directions? Without the fix: 3 documented master failures over 30 days with the same retry-exhaustion signature. With the fix: passing runs still break out of the loop on the first iteration, so there is no added latency on the happy path. CI on this PR will validate the deb install path on the same Install packages (amd_release) job.

f. Fix is general, not a narrow patch? Considered: binary_test in the same file also uses a 5-iteration loop, but it has no documented failure history and the binary_test path is different (clickhouse-server start --daemon, not init.d). I deliberately did not touch it. The initd_via_systemd_test block uses systemd's notify protocol and does not race, so it also stays as-is.

Session: cron:clickhouse-ci-task-worker:20260528-143000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @leshikus — could you review? It's a one-line CI test fix bumping the retry loop from 5 to 30 iterations to absorb slow listener bind on the Install packages (amd_release) host (3 master hits in 30 days).

@leshikus leshikus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix does not make the code worse, yet the polling design is prone to errors. Better to use callbacks instead when possible.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label May 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4bc9ee0]

Summary: ✅


AI Review

Summary

This PR extends the Run server init.d readiness poll in ci/jobs/install_check.py from five to thirty attempts after the init.d wrapper returns. The code change matches the observed clickhouse-client Connection refused retry exhaustion and does not weaken the package/environment assertion, but the affected PR job has not validated the changed path yet.

Tests
  • ⚠️ The Install packages (amd_release) report for PR head 4bc9ee07c4c0eac0b8cde8d2addb8cbf1c417a8f is still PENDING with zero test results, so Run server init.d has not shown a passing run with the extended retry budget. Let that job complete or rerun it and confirm the test passes.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: get a passing Install packages (amd_release) run on the PR head, including Run server init.d.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 28, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 29, 2026
Merged via the queue into ClickHouse:master with commit 70b4eb0 May 29, 2026
166 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 May 29, 2026
alexey-milovidov added a commit that referenced this pull request Jun 30, 2026
Fix flaky `Run server init.d` install check on 25.8 (backport of #106056)
@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov could you apply v26.3-must-backport to this PR?

ci/jobs/install_check.py still has the 5s retry budget on 26.5 and 26.3 (the file is
byte-identical on both); 26.6 and 26.7 branched after this merged and already have it. The 5s
budget is still producing red Install packages jobs on 26.5: 4 hits in 120 days, the latest on
26.5.7.38 at https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=26.5&sha=3dfa1ee11d8f27ce1fecfa7da55adba8b6374100&name_0=ReleaseBranchCI&name_1=Install%20packages%20%28amd_release%29

Both forms have been running side by side since this merged: 4 failures of this signature in 863
runs on the 5s branches, 0 in 4119 runs on the 30s branches. I have no measured failures on 26.3
itself, so that half is just the same file riding along on one label rather than an observed red.

v26.3-must-backport expands to 26.7, 26.6, 26.5, 26.3, and pre_check skips 26.7/26.6 because
the merge commit is already an ancestor there, so it produces exactly the two PRs that are
missing. I simulated both: each is a clean one-file +4/-2 whose hunk is byte-identical to this
PR's, so the robot should open the backport PRs directly with no cherry-pick step. I have not
touched the release branches.

kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
The `initd_test` script in `ci/jobs/install_check.py` on `25.8` runs
`clickhouse-client -q 'SELECT version()'` exactly once, immediately after
the init.d wrapper prints `Server started`. The wrapper only checks that
the pid file exists, but on a slow CI host (notably the `amd_debug` build)
the server can take several seconds longer to open the TCP listener on
port 9000. The test then fails with
`Code: 210. DB::NetException: Connection refused (localhost:9000)`.

In the same job the sibling `binary_test` already retries `SELECT version()`
in a loop, and on `25.8` backport runs it routinely takes ~4 seconds (4
retries) before the debug server accepts connections, while `initd_test`
gives up after the first attempt.

This is the same failure mode as ClickHouse#86278, which was fixed on `master` by
ClickHouse#106056 ("Extend `Run server init.d` retry budget from 5s to 30s"). That
fix never reached `25.8`, so the flake keeps blocking `25.8` backport PRs
(for example ClickHouse#108965 and ClickHouse#108917). Because the `25.8` `initd_test` predates
the retry loop entirely, ClickHouse#106056 does not cherry-pick cleanly; this commit
adapts the same fix by adding a 30-iteration poll loop that breaks early on
success, matching the existing `binary_test` and `keeper_test` patterns.

`SYSTEMCTL_SKIP_REDIRECT` is intentionally not added, since the `25.8`
init.d script does not support it.

Related: ClickHouse#86278, ClickHouse#106056

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

CI: Run server init.d failed

5 participants