Repository navigation
Conversation
…st setup A stale clickhouse-server/keeper from a previous run in the same job container can still hold 9000/8123/9181/9009 when the stateless functional test setup starts a fresh server. Because the CI config sets listen_try=true, the fresh server logs each Listen ... Address already in use only as a Warning, stays alive but never listens on the TCP port, so wait_ready() times out with Code 210 and the job fails at setup before any test runs. ClickHouseProc.start() now frees the key server ports before launching replica 0: it detects held ports with ss, kills any lingering clickhouse-server/keeper, and waits for the sockets to be released. Best-effort and never raises, so it cannot mask a real start failure. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-2:20260707-191200 |
|
cc @maxknv @leshikus — could you review this? It fixes a stateless flaky-check setup failure: a leftover clickhouse-server/keeper from a prior run in the same job container holds 9000/8123/9181/9009, and because the CI config sets listen_try=true the fresh server logs the bind failures only as Warnings, stays up but never listens, so wait_ready() times out (Code 210) before any test runs. start() now frees those ports (kill lingering server/keeper + wait for release) before launching. |
| # before we launch our own (listen_try=true otherwise turns a port | ||
| # collision into a silent wait_ready timeout). Done once, before any | ||
| # of our replicas start, so it only ever targets stale processes. | ||
| self._ensure_server_ports_free([9000, 8123, 9181, 9009]) |
There was a problem hiding this comment.
@groeneai at stress_runner.sh it also waits for server ports to be free, and there are more than those. Can you check and update this list?
Per review: reconcile the port-teardown list with the authoritative wait_server_ports_free() in tests/docker_scripts/stress_tests.lib. A stateless test server listens on more than the four native/http/keeper/ interserver ports, so free the full set (adds https 8443, mysql 9004, postgres 9005, tcp-proxy 9010, ssh 9022, grpc 9100, keeper-raft 9234, native-tls 9440, prometheus 9988) before starting. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@PedroTadim good catch. Reconciled the teardown list with the authoritative
= HTTP, HTTPS, native TCP, MySQL, PostgreSQL, interserver HTTP, TCP-proxy, SSH, gRPC, Keeper, Keeper-Raft, native-TLS, Prometheus. This is the same set our own replica_command_1/2 bind (tcp_port_secure/mysql/postgresql/interserver/prometheus/etc), so the teardown now covers every port a leftover server or keeper could still hold. |
|
Duplicates |
Remove the duplicated port list: define CLICKHOUSE_SERVER_PORTS once in tests/docker_scripts/stress_tests.lib and have both wait_server_ports_free() (bash) and clickhouse_proc.py's setup teardown read it, so the two lists can no longer drift. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@leshikus done in 321dd56. Removed the duplicated list: I kept the setup teardown as a separate function rather than calling the bash helper directly because they do different things and run in different contexts: |
|
Workflow [PR], commit [321dd56] AI ReviewSummaryThis PR adds a pre-start cleanup in Findings
Final VerdictStatus: Minimum required action: make the pre-start teardown cover leftover replica |
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok.
@groeneai, now does it makes sense to also remove listen_try from the CI? So the errors will be instantly visible?
| # collision into a silent wait_ready timeout). Done once, before any | ||
| # of our replicas start, so it only ever targets stale processes. | ||
| # Port set is single-sourced from stress_tests.lib (see _server_ports). | ||
| self._ensure_server_ports_free(self._server_ports()) |
There was a problem hiding this comment.
start(replica_num=0) later fans out into replicas 1 and 2, but this cleanup only probes the base CLICKHOUSE_SERVER_PORTS set from stress_tests.lib. If the previous run leaked only replica 1 or 2, all of the ports checked here can be free while 19000/18123/19181 or 29000/28123/29181 are still occupied by the stale process. In that case we skip the pkill entirely and hit the same listen_try-masked wait_ready() timeout when the new replica starts. The teardown needs to cover the shifted replica port sets as well (or kill stale ClickHouse processes unconditionally in replicated mode), otherwise the fix still misses database-replicated jobs.
There was a problem hiding this comment.
Good catch. Fixed in fe015fa: in db-replicated mode the teardown now also probes the shifted replica-1/2 port sets, derived from the authoritative replica_command_1/2 strings (19000/18123/19181..., 29000/28123/29181...), not a second hard-coded list. A leaked replica 1/2 now triggers the pkill instead of slipping past the base-port probe.
In database-replicated mode replicas 1 and 2 bind shifted port sets (19000/18123/19181..., 29000/28123/29181...) rather than the base CLICKHOUSE_SERVER_PORTS. A leaked replica 1/2 leaves the base ports free, so the teardown skipped pkill and the stale process still held the shifted ports, recreating the listen_try-masked wait_ready timeout for replicated jobs. Derive the shifted ports from the authoritative replica_command_1/2 strings (no second hard-coded list) and probe them too when db-replicated. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260712-145000 |
|
This PR looks superseded by #110122 ("CI: kill leftover clickhouse server processes before the first server start"), which merged into master on 2026-07-13. #110122 fixes the identical root cause — a leftover As a result this branch now conflicts with master and
Given that, I'd recommend closing this as superseded by #110122. If any incremental piece is still worth keeping — e.g. single-sourcing the port list via |
|
Agreed, closing as superseded by #110122. Confirmed it covers the same root cause more generally: pattern-killing No incremental follow-up needed for now: the single-sourced |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Free leftover server ports before starting ClickHouse in the stateless functional-test setup, so a stale
clickhouse-server/clickhouse-keeperfrom a previous run in the same job container cannot silently break the fresh server.Root cause: the CI test config sets
listen_try=true(tests/config/config.d/listen.xml). When a lingering server still holds9000/8123/9181/9009, the fresh server logs eachListen ... Address already in useonly as a Warning, stays alive, but never listens on the TCP port.wait_ready()then times out withCode: 210. Connection refused (localhost:9000)and the job fails at setup, before any test runs — reported as an opaqueSETUP FAILURE: clickhouse-server not ready (wait_ready). This surfaced as a false-redStateless tests (*, flaky check)verdict (the changed test never executed) and recurs across many unrelated PRs.Fix:
ClickHouseProc.start()now runs a best-effort teardown once, before starting replica 0. It checks whether9000/8123/9181/9009are held (ss -Hlnt 'sport = :PORT'); if so it kills any lingeringclickhouse-server/clickhouse-keeperand waits (up to 45s) for the sockets to be released before launching our own process. It never raises, so a failure here cannot mask a real start error;wait_ready()still reports if the server genuinely cannot listen.