Repository navigation
Retry clickhouse-server boot in functional-test setup - #109115
alexey-milovidov merged 6 commits into
Conversation
A transient host condition at boot (e.g. a brief memory spike from a co-tenant job on the same runner) can make clickhouse-server exit a few seconds after start, before it even creates its err.log, with no diagnostics. A plain re-start then succeeds. This showed up as an opaque "Start ClickHouse Server" setup FAIL across several unrelated PRs in the same short window, reddening the non-blocking Bugfix validation job (and thus Finish Workflow / Mergeable Check) even though the server binary was healthy - proven by every other server-booting check passing on the same commit, and by a same-SHA rerun of a sibling PR passing. Retry the initial setup boot up to 3 times: on a failed start/wait_ready, stop the server, clean its logs, wait briefly, and try again. A single transient boot death no longer fails the whole job; a persistent boot failure still fails after the last attempt with wait_ready()'s err-log tail preserved for triage, so a real boot regression is not masked. The first-try-success path is unchanged, and the per-build-type binary-swap boot stays fail-closed. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260702-041500 |
|
cc @maxknv @leshikus — could you review this? It retries the initial clickhouse-server boot (up to 3x: stop_server → clean_logs → sleep → restart) in the functional-test setup, so a transient boot death (server exits ~115 before writing err.log, recovered by a plain restart) no longer FAILs the whole non-blocking Bugfix validation job and reddens Finish Workflow / Mergeable. A persistent boot failure still fails closed after the last attempt with the err-log tail preserved; the first-try-success path is unchanged. |
|
Workflow [PR], commit [94b622c] Summary: ✅ AI ReviewSummaryThis PR retries the initial functional-test Findings❌ Blockers
Final VerdictChanges required. Do not merge until LLVM Coverage Report |
ClickHouseProc.start() returns False after a 15s timeout waiting for the pid file, but on that path it still spawned the server (self.proc is set) and never recorded self.pid_0/1/2. stop_server() only acts when both proc and the recorded pid are truthy, so for the slow / late-pid-file boot it was a no-op and left the spawned server running. The setup boot-retry loop calls stop_server() before restarting, so on a slow start the previous server was left alive while the next attempt unlinked the pid file, wiped run_path, and spawned a second server on the same directories. Handle the proc-but-no-pid case: kill any live server for that replica by its unique --pid-file command-line token, then reap the process handle. pkill -f is used because proc may be the `sh -c` wrapper rather than the server itself (subprocess.Popen(..., shell=True) does not always exec), so terminating proc alone can orphan the server; matching the token reaches the wrapper, the server, and any leaked duplicate. The normal running-server path (proc and pid both set) is unchanged. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Updated pre-PR validation gate for HEAD 8e01c41 (adds the stop_server hardening from the bot review). Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260702-074400 |
stop_server() decides between its graceful path and the pid-less kill path from self.pid_0/1/2, but start() only ever assigned those fields, never reset them. It unlinks the pid file at the top of every spawn, so after one successful boot the cached pid outlived the file it mirrors: on a later slow start, where the pid file does not appear inside the 15s poll, self.proc pointed at the new `sh -c` wrapper while self.pid_0 still held the previous server's pid. stop_server() then took the graceful branch on a pid that is not this server's and the pid-less kill path added in 8e01c41 never ran, so the slow-starting server was left alive - exactly the leak that path exists to prevent, and the state the boot-retry loop then restarts on top of. Measured against the real start()/stop_server() with `clickhouse stop` from a release binary, driving the claim's premise (pid file late, server a child of the wrapper): before, pid_0 carried over, the graceful branch ran, `clickhouse stop --pid-path` exited 107 (FILE_DOESNT_EXIST, so a missing pid file is a hard failure rather than a silent success), the escalation sent SIGTRAP to the `sh` wrapper, and the server survived stop_server(); after, pid_0 was 0, the pid-less kill path ran, and the server was gone. Both arms had the same live wrapper/server tree before the stop. Reset the cached pid next to the pid-file unlink, so the two are cleared together, and route both writes through one _set_pid() helper instead of repeating the replica dispatch. Also trim the comments this PR had accumulated over its review rounds down to the local invariants: why the pid-less path matches on the --pid-file token rather than signalling proc, and that only the setup boot is retried. The transient-host-condition background and the cross-PR evidence live in the commit messages, not in the source. Co-Authored-By: Claude Opus 5 <[email protected]>
`.claude/CLAUDE.md` asks for literal class, function and option names inside inline code blocks, and for a function to be named `f` rather than `f()`. Co-Authored-By: Claude Opus 5 <[email protected]>
`wait_ready` fails in two different states and only one of them was ever shown to be transient. It returns False through its `proc.poll()` branch when the server exited, which is the boot death this loop exists for, and through its readiness timeout while the process is still up. Retrying the second state is unsafe: the next attempt's `start` calls `Utils.clean_dir` on `run_path`, so it would wipe the directory a live server is using. `stop_server` does not save it either, because when `clickhouse stop --do-not-kill` reports the server is still running (`Install.cpp`, `stop`, returns 1 in that case) the escalation signals `proc`, which is the `sh -c` wrapper rather than the server. Break out of the loop while the process is still alive, so that state fails with `wait_ready`'s own diagnostics exactly as it did before this loop existed. Measured with the real `start` and `wait_ready`: a server that exits 115 takes the `proc.poll()` branch and leaves `poll` at 115, so it is still retried; a server that stays up and never answers `select 1` takes the timeout branch after 63s and leaves `poll` at None, so it is not. Co-Authored-By: Claude Opus 5 <[email protected]>
With `DatabaseReplicated`, `start` also spawns replicas 1 and 2, and `wait_ready` returns as soon as replica 0 fails, before it looks at the other two. Gating on replica 0 alone therefore still allowed a retry while a sibling replica was up, and `start` clears each replica's run directory in turn. Gate on every tracked replica instead. Nothing changes when the job is not replicated, where `proc_1` and `proc_2` are None. Measured over real `Popen` handles: (dead, None, None) and (dead, dead, dead) retry, while (dead, alive, None), (dead, None, alive) and (alive, None, None) do not. Co-Authored-By: Claude Opus 5 <[email protected]>
| elif proc: | ||
| # `proc` is the `sh -c` wrapper, not the server, so kill by the | ||
| # unique --pid-file token, then reap the wrapper. | ||
| Shell.check(f"pkill -9 -f -- '--pid-file {pid_file}'", verbose=True) |
There was a problem hiding this comment.
The new elif proc branch fixes the pid-less case, but the same wrapper problem still exists a few lines above once a pid was recorded. This function now documents that proc is only the sh -c wrapper; a minimal sh -c "sleep 1000" trace leaves the child alive after kill -TRAP $wrapper, so if clickhouse stop --pid-path ... falls through, proc.send_signal(signal.SIGTRAP) / proc.kill() can return with the real clickhouse-server still running. The retry and bugfix-validation restart then continue on dirty process state, and terminate(force=True) callers still leak the server for the same reason.
Please escalate against the real server process (pid) or reuse the same pkill -f -- '--pid-file ...' cleanup after the graceful stop fails, instead of signalling the wrapper.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Retry the initial clickhouse-server boot in the functional-test setup so a single transient boot death does not fail the whole job.
Description
Problem. In functional-test setup,
startspawns the server andwait_readypollsselect 1. A transient host condition at boot, such as a brief memory spike from a co-tenant job on the same runner, can make the server exit a few seconds in, before it createsclickhouse-server.err.log, so no diagnostics survive. A plain re-start then succeeds. It surfaces as an opaqueStart ClickHouse Serversetup FAIL, reddening the non-blockingBugfix validation (functional tests)job and, through the rollup,Finish WorkflowandMergeable Check.Evidence it is transient. In one 40-minute window the identical failure hit four unrelated PRs. On the commit that failed this step every other server-booting check passed, including Fast test, all Integration batches, AST fuzzer, BuzzHouse and Stress, and a sibling PR re-ran the same SHA and passed. Failing run: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109052&sha=f03fe3af507daaf0a255f0cdc55867bc05662e59&name_0=PR&name_1=Bugfix%20validation%20%28functional%20tests%2C%20amd64%29
Fix. Retry the setup boot up to 3 times, but only a boot the server did not survive.
wait_readyalso fails by readiness timeout while the process is still up, and retrying that would let the next attempt'sUtils.clean_dirwipe the run directory a live server is using, so the loop stops while any tracked replica is alive and fails withwait_ready's own diagnostics. A persistent boot failure still fails after the last attempt with the err-log tail preserved. The first-try-success path is unchanged, and the per-build-type binary-swap boot stays fail-closed.clickhouse_proc.pycarries the twostop_serverfixes the retry depends on: it now kills a server whose pid file never appeared withinstart's poll, previously a silent no-op that left it running, andstartclears the cached pid it had only ever assigned, so that path is reachable on a retry instead of shadowed by the previous attempt's pid.Workflow [PR]
Sync PR [sync-upstream/pr/109115]
Version info
26.10.1.781-master(included in26.10and later)