Repository navigation
CI: kill leftover clickhouse server processes before the first server start - #110122
Conversation
… start Runners are reused across jobs, and a job that is cancelled or times out can leave its `clickhouse-server` running or slowly shutting down. Such a leftover keeps the server ports, so the next job's server fails every listen with `Address already in use` and `wait_ready` times out with an opaque `Connection refused`, failing the whole job at the `Start ClickHouse Server` step. Observed in the "Stateless tests (amd_debug, flaky check)" job: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105249&sha=0fc7d64da40e5f01b107434f039acaede261af12&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 on #105249 - the first server start of the job got `Address already in use` on every port (9181, 9009, 8123, 9000, ...), so a full server instance from a previous job was still alive on the runner. The cleanup runs in `ClickHouseProc.start` for replica 0 only, next to the analogous `dmesg --clear` cross-job hygiene. All server processes are stopped before every replica-0 start (`stop_server` precedes the mid-job restart in bugfix validation), so anything matching at that point is stale by definition. The cleanup never runs locally, where the machine may host a developer's own server. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [131ed3c] Summary: ✅ AI ReviewSummaryThis PR factors a pre-start Findings❌ Blockers
Tests
Final Verdict
|
| if replica_num == 0: | ||
| # Clear dmesg to avoid false OOM detection from previous CI jobs on the same host | ||
| Shell.check("dmesg --clear", verbose=True) | ||
| self._kill_leftover_server_processes() |
There was a problem hiding this comment.
This only applies the stale-runner cleanup to ClickHouseProc.start, but the same Start ClickHouse invariant still has sibling entrypoints that launch clickhouse-server on fixed shared ports without any cleanup: start_light (used by ci/jobs/clickbench.py, ci/jobs/vector_search_stress_job.py, and ci/jobs/vector_search_stress_tests.py) and the duplicate ClickHouseBinary.start helpers in ci/jobs/sqltest_job.py, ci/jobs/sqllogic_test.py, and ci/jobs/sqlstorm_test.py. A reused runner with a leaked server will still fail those jobs with the same Address already in use / wait_ready pattern, so the fix is only partial. Please move this into a shared pre-start helper and call it from every CI server-start path.
There was a problem hiding this comment.
Addressed in 30b0f2044cc: factored the cleanup into a shared ci/jobs/scripts/server_cleanup.py helper (kill_leftover_server_processes) and call it right before the first server start from every host entry point — ClickHouseProc.start_light (functional/fast/fuzzer/clickbench/vector-search jobs) in addition to ClickHouseProc.start (replica 0), plus the duplicate ClickHouseBinary.start helpers in sqltest_job.py, sqllogic_test.py, and sqlstorm_test.py. The Info().is_local_run guard is preserved everywhere.
There was a problem hiding this comment.
The coverage is still incomplete. Quick functional tests starts clickhouse server directly on the host in ci/jobs/clickhouse_light.py:119-127 (ci/defs/job_configs.py:624-634), and Collect ClickHouse Profiles starts servers in ci/jobs/collect_clickhouse_profiles.py:463-474 and ci/jobs/collect_clickhouse_profiles.py:283-305 while its job uses clickhouse/binary-builder+--network=host (ci/defs/job_configs.py:23-27, ci/defs/job_configs.py:1514-1518). A leaked server from a cancelled or timed-out previous job can still make those jobs fail with the same Address already in use / readiness-timeout pattern, so the "every host entry point" part is not true yet.
There was a problem hiding this comment.
The current cleanup still misses the original failure mode for the Docker-based jobs. kill_leftover_server_processes only does pgrep/pkill inside the current process namespace (ci/jobs/scripts/server_cleanup.py:26-36), but Praktika starts these jobs with plain docker run and never adds --pid=host (ci/praktika/runner.py:458). That means a cancelled previous job can leave a host-network container still running, holding ports like 9000/8123, and the fresh container for functional_tests / fast_test / clickbench / collect_clickhouse_profiles (ci/defs/job_configs.py:101, ci/defs/job_configs.py:209, ci/defs/job_configs.py:1329, ci/defs/job_configs.py:1518) still cannot see or kill that stale clickhouse-server, so Address already in use remains reproducible.
There is also still an uncovered host-network start path in the AST/BuzzHouse fuzzer flow: the job launches a nested docker run --network=host in ci/jobs/ast_fuzzer_job.py:123-133, and that container starts clickhouse-server in ci/jobs/scripts/fuzzer/run-fuzzer.sh:129-135. The cleanup needs to happen at the host / Docker-container level before the new job starts, not only via pgrep inside the new job's namespace.
Address the AI review (⚠️ Request changes) on PR #110122: the stale-process cleanup was wired only into `ClickHouseProc.start`, so the other CI entry points that launch `clickhouse-server` on the host still hit the same reused-runner port conflict (`Address already in use` -> `wait_ready` timeout with an opaque `Connection refused`). Factor `kill_leftover_server_processes` into a shared `ci/jobs/scripts/server_cleanup.py` helper and call it right before the first server start from every such entry point: - `ClickHouseProc.start` (replica 0) and `ClickHouseProc.start_light`, covering the functional, fast, fuzzer, clickbench and vector-search jobs; - the duplicate `ClickHouseBinary.start` helpers in `sqltest_job.py`, `sqllogic_test.py` and `sqlstorm_test.py`. The helper keeps the `Info().is_local_run` guard so it never touches a developer's own server on a shared machine. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The AI review found two more entry points that start `clickhouse-server` on fixed shared runner ports without the pre-start cleanup: `Quick functional tests` (`clickhouse_light.py`) and `Collect ClickHouse Profiles` (`collect_clickhouse_profiles.py`, both its temporary dataset server and the profiled server). A server leaked by a cancelled or timed-out previous job can still make these jobs fail with `Address already in use` and a readiness timeout before their first server start. Call `kill_leftover_server_processes` right before the first server start in each: - `ClickHouseSetup.start_server` (gated on the first start so a later restart does not kill the job's own server), - `main` in `collect_clickhouse_profiles.py` (a single call before the sequential PGO/BOLT dataset and profiled server starts), - `ClickHouseService.__enter__` (the `CI Tests` job), found by auditing all remaining server-launch sites. The performance-comparison job (`performance_tests.py`) is intentionally left untouched: it runs two concurrent servers (Reference and Patched), so a blanket pre-start kill would kill one while the other is running. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI review "Request changes" in Extended the pre-start
While there, I audited every other server-launch site so this converges:
Verified with |
|
On the AI "❌ Blockers" verdict — I dug into the execution model and the finding is correct: as currently written the cleanup cannot reach the cross-job leftover it targets. Evidence:
So the mechanism only works for a job that runs directly on the host (host PID namespace, where The two ways to actually fix it are both CI-architecture decisions, so I'm leaving them to you rather than changing them unilaterally:
Which one is right depends on how these runners actually leak (an orphaned still-running container vs a bare host process) and whether a runner is single-job — I can't determine either from the code. Happy to implement whichever you pick. My last commit ( |
…r-server-processes # Conflicts: # ci/jobs/collect_clickhouse_profiles.py
Address the AI review "Request changes" Major: `ClickBench` starts the server through `ClickHouseProc.start_light`, whose cleanup now lives in `clickhouse_proc.py` and the new `server_cleanup.py`, but the job's `digest_config` listed neither. Praktika's `Job.Config.is_affected_by` therefore returned `False` for both `ClickBench` jobs on this PR, so the changed start path was never exercised, and any future change confined to the shared helper would bypass the job again. Add `server_cleanup.py` (and, for `ClickBench`, `clickhouse_proc.py`) to the `digest_config` of every job that reaches `kill_leftover_server_processes` at runtime and has a restrictive `include_paths`: `ClickBench`, `Fast test` (shared `fast_test_digest_config`, also feeding the Darwin variant), stateless functional tests, `Quick functional tests`, `SQL test`, `SQL logic test`, `SQL storm test`, and `Collect ClickHouse Profiles`. `CI Tests` already includes the whole `./ci` tree, so it needs no change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| Runners are reused across jobs, and a job that is cancelled or times out | ||
| can leave its clickhouse-server running or slowly shutting down. Such a | ||
| leftover keeps the server ports, so the next job's server fails every | ||
| listen with `Address already in use` and its `wait_ready` times out with | ||
| an opaque `Connection refused`. |
There was a problem hiding this comment.
The only concrete report cited for this failure mode (Stateless tests (amd_debug, flaky check) on PR #105249) is not actually a leaked-process case. Its clickhouse-server.log shows one fresh server process starting normally, then receiving SIGTERM exactly when the 60s wait_ready budget expires; the earlier Address already in use messages are the expected dual-stack [::]/0.0.0.0 warnings from tests/config/config.d/listen.xml plus listen_try=true, not another server already holding the ports.
So this helper is still unproven against the example in the PR description, and if that flaky-check timeout is the bug we care about, this change will not fix it. Can we either point to a real leaked-process report or add a focused repro that leaves a stale clickhouse-server in the same namespace and shows the next start succeeding?
There was a problem hiding this comment.
Verified against the actual log for that run (.../stateless_tests_amd_debug_flaky_check/clickhouse-server.log) — this is correct, there was no leaked server:
- One process only (pid 633, forked
21:17:08.427). - Every
Address already in useis a[0.0.0.0]:<port>bind immediately followed by a successful[::]:<port>bind of the same port — the expected IPv4-after-IPv6 dual-stack duplicate underlisten_try=true. E.g.Listen [0.0.0.0]:9000 failedat21:18:11.621->Listening for native protocol (tcp): [::]:9000at21:18:12.930. - The server bound
[::]:9000~64.5s after fork, just past the 60swait_readybudget;SIGTERM(Received signal 15) had already arrived at21:18:11.450when the harness gave up.
So this is a slow debug-build readiness timeout, not a stale clickhouse-server holding ports — the pre-start pkill would not have changed the outcome, and (per the other thread) it cannot reach a cross-job leftover in a separate PID namespace anyway. This report does not justify the change; the real signal here is the readiness budget for slow debug/sanitizer builds. I will not add a same-namespace repro, since it would not reflect the actual failure.
…r-server-processes
Address the AI review (⚠️ Request changes) on PR ClickHouse#110122: the stale-process cleanup was wired only into `ClickHouseProc.start`, so the other CI entry points that launch `clickhouse-server` on the host still hit the same reused-runner port conflict (`Address already in use` -> `wait_ready` timeout with an opaque `Connection refused`). Factor `kill_leftover_server_processes` into a shared `ci/jobs/scripts/server_cleanup.py` helper and call it right before the first server start from every such entry point: - `ClickHouseProc.start` (replica 0) and `ClickHouseProc.start_light`, covering the functional, fast, fuzzer, clickbench and vector-search jobs; - the duplicate `ClickHouseBinary.start` helpers in `sqltest_job.py`, `sqllogic_test.py` and `sqlstorm_test.py`. The helper keeps the `Info().is_local_run` guard so it never touches a developer's own server on a shared machine. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…over-server-processes CI: kill leftover clickhouse server processes before the first server start
Related: #105249
CI runners are reused across jobs, and a job that is cancelled or times out can leave its
clickhouse-serverrunning or slowly shutting down. Such a leftover keeps the server ports, so the next job's server fails every listen withAddress already in useandwait_readytimes out with an opaqueConnection refused, failing the whole job at theStart ClickHouse Serverstep.Observed in the "Stateless tests (amd_debug, flaky check)" job of #105249: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105249&sha=0fc7d64da40e5f01b107434f039acaede261af12&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29 — the very first server start of the job got
Address already in useon every configured port (9181, 9009, 8123, 8443, 9000, ...), so a full server instance from a previous job was still alive on the runner. The job then failed before running a single test.This adds a cleanup to
ClickHouseProc.startfor replica 0 only, next to the analogousdmesg --clearcross-job hygiene ("to avoid false OOM detection from previous CI jobs on the same host"). All server processes are stopped before every replica-0 start (stop_serverprecedes the mid-job restart in bugfix validation), so any process matchingclickhouse[- ]serverat that point is stale by definition and is killed, with thepssnapshot logged tojob.logand a workflow warning added for visibility. The cleanup never runs locally (is_local_run), where the machine may host a developer's own server that must not be touched. The performance comparison job uses its ownCHServerclass with two concurrent servers and is not affected.Changelog category (leave one):
Version info
26.7.1.875(included in26.7and later)