Repository navigation
Collect RabbitMQ diagnostics once instead of until a second timeout expires - #113610
PedroTadim merged 3 commits into
Conversation
…xpires
`ClickHouseCluster.wait_rabbitmq_to_start` has two loops. The first polls
readiness until its 120s deadline. The second collects the container log plus
`rabbitmq_debuginfo` for the report, but it has no `break` and sleeps only in
its `except` arm, so whenever collection succeeds it keeps re-collecting until
a second full 120s deadline expires before raising.
That is the normal path, because `rabbitmq_debuginfo` runs its three
`rabbitmq-diagnostics` subprocesses through `Popen`/`communicate` without
checking their return codes, so collection cannot fail even against a broker
that never started.
Measured against a real `rabbitmq:4.2.1-management-alpine` container whose
broker never boots, which is the condition the failing CI jobs are in: the
loop runs 21 collections and spends 121.35s, spawning 63 `rabbitmq-diagnostics`
invocations against an already wedged container. Three failing CI jobs show the
same interval between the last readiness probe and the RuntimeError: 121.7s,
121.1s and 121.8s, with `Unable to get logs from docker` absent, confirming that
collection succeeded on every iteration there too. With the `break`, one
collection runs and the function proceeds straight to the raise.
The `break` is the last statement of the `try` block, so a collection that does
fail still retries to the deadline as before.
This changes the cost of the failure, not its verdict. The `raise
RuntimeError("Cannot wait RabbitMQ container")` after the loop is
unconditional, and the loop is only reachable once the readiness deadline has
already expired, so no run that passes today executes this line.
`wait_kafka_is_available` in the same file is the precedent, and its placement
is stricter than a `break`: it collects its diagnostics in a `try` placed
outside its wait loop, so collection there can only happen once by
construction. Of the 36 `wait_*` helpers in this file, three collect
diagnostics at all, the other two being `wait_kafka_is_available` and
`wait_minio_to_start`, and `wait_rabbitmq_to_start` is the only one that does so
inside a deadline loop.
Nothing pinned the preceding change. The readiness loop returns on success, so every healthy fixture leaves `wait_rabbitmq_to_start` before reaching the collection loop, and deleting the `break` again would leave every existing test green. The new test needs no Docker, no broker and no `ClickHouseCluster` instance, and runs in about three seconds. It loads `wait_rabbitmq_to_start` out of `helpers/cluster.py` by AST extraction and executes it against stubs with a one second deadline, so it tracks the shipped source rather than a copy of it. Four cases. Readiness fails and collection succeeds: exactly one collection and one `rabbitmq_debuginfo`, then the `RuntimeError`. Readiness fails and collection fails: more than one collection, so retry to the deadline survives. Healthy broker: the waiter returns `True` having collected nothing, which is a reachability control rather than a witness, since it is green with or without the `break`. Plus an assertion that the `break` is the last direct statement of the `try` body. That last assertion is positional on purpose. A `break` moved below the `try`/`except` still satisfies a subtree membership test, and still stops the spin on the path where collection succeeds, while silently dropping the retry on the path where it fails. Deleting the `break` fails the first case, moving it below the `try`/`except` fails only the second, and the positional assertion catches both. It lives under `test_*/` because `tests/integration/pytest.ini` sets `python_files = test_*/test*.py` and the CI job enumerates `test_*/test*.py`, so a file under `helpers/` would never run.
The mocked test added in the previous commit injected the real time module into the extracted waiter, so it executed real sleeps: the suite cost 3.14s and, more importantly, its retry arm was wall-clock bounded. At the 1.0s deadline it ran exactly 2 collection attempts against an `assert counts["logs"] > 1`, so a single 0.5s scheduling overshoot on a loaded runner would have collapsed it to one attempt and reddened correct code. `> 1` was also weaker than the contract the change claims: it is satisfied by an implementation that retries once and stops. Inject a fake clock that advances only when the code under test sleeps. The test can then use the helper's own default 120s deadline while every arm stays instant, and every retry count becomes exact: 240 = 120 / 0.5, the collection loop retrying until its own deadline expires. The counts were derived from the loop structure first and then observed to match; 0.5 and 1.0 are binary-representable, so the accumulated clock lands on exactly 120.0 and 240.0 with no drift. A clock that only advances on sleep needs one guard. With the break reverted and collection succeeding, the loop body never reaches its except arm and so never sleeps, which would leave it spinning until pytest's 900s timeout instead of failing on an assertion. The clock therefore caps its read count and fails immediately with a message naming the spin. The cap cannot fire on correct code: the four arms read the clock 124, 364, 364 and 2 times, so it has 275x headroom. Also add a third failure arm. The guarded block has two operations that can raise, `subprocess.check_call` and `rabbitmq_debuginfo`, and only the first was ever made to fail. Since debuginfo runs second, both counters advance together there, which is what pins that the break sits after both operations rather than between them. Suite: 5 cases, 0.29s, 20 consecutive runs green. Mutation matrix re-run in a scratch jail under the repository's own 900s timeout, never mutating the shipped helper: deleting the break fails the success arm and the positional assertion; moving it below the except arm fails only the two retry arms and the positional assertion, leaving the success arm green; and capping the collection loop at two attempts fails both retry arms under the exact counts while it would have passed under the old inequality, which is what shows the exact counts are load-bearing.
Internal second-model review (4 rounds, findings adjudicated)I run every change through an independent review pass plus a second model before opening Round 1 (on an earlier, larger change)❌ Blocker, AGREED. The earlier version of this change also raised the readiness ❌ Blocker, AGREED. With that half gone, the remaining change does not fix the
Round 2 (on this change)
Round 3
💡 Nit, AGREED, found while implementing the above. The faked clock removes the Round 4
💡 Nit, AGREED. The description called the Kafka precedent's collection block a "bare 💡 Nit, DISAGREED. Dropping the What I verified rather than assumed
|
Pre-PR validation gate (click to expand)
|
|
cc @qoega, could you review this? The diagnostic-collection loop in wait_rabbitmq_to_start has no break and sleeps only in its except arm, so once collection succeeds it re-collects until a second full 120s deadline expires before raising; the break makes it collect once, and a collection that does fail still retries as before. |
|
Workflow [PR], commit [ce968ed] Summary: ✅ AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
|
cc @pamarcos |
CI finish ledger — ce968edEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task 175 check-runs, all completed: 32 success / 143 skipped / 0 failure.
Session id: cron:our-pr-ci-monitor:20260806-133000 |
231a48a
When a RabbitMQ container fails to become available, wait_rabbitmq_to_start raises and every test in the affected module fails from that one event. The broker's own log, the artifact that would say why the node never started, does not survive the run. rabbitmq.conf sets log.file = /rabbitmq_logs/rabbit.log and no log.console, so everything the broker logs goes to that file and nothing to the console, which is also why the docker logs capture produces an empty file. The compose file declares /rabbitmq_logs as tmpfs, so the log dies with the container. cluster.py has always exported RABBITMQ_LOGS and RABBITMQ_LOGS_FS="bind" and created the host directory, but no compose file consumed them after 545bb5b replaced the bind mount with a tmpfs entry. RabbitMQ was the only broker whose *_LOGS export was dead. Restore the mount in the same ${VAR_FS:-tmpfs} / ${VAR:-} form the live sibling compose files use, so an unset RABBITMQ_LOGS still degrades to tmpfs. /var/lib/rabbitmq stays a tmpfs: it holds Mnesia state, and persisting it across runs would change test semantics. The log lands in _instances*/rabbitmq/logs/, which the integration job already tars. This neither stops the module abort nor explains why the Erlang node failed to register with epmd. ClickHouse#114415 recreates a hung container; this makes the next occurrence diagnosable. ClickHouse#113610 fixed only the second diagnostics loop of wait_rabbitmq_to_start and is not a container-start fix.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
ClickHouseCluster.wait_rabbitmq_to_starthas two loops. The first polls readinessuntil its 120s deadline. The second collects the container log plus
rabbitmq_debuginfofor the report, but it has nobreakand sleeps only in itsexceptarm, so whenever collection succeeds it keeps re-collecting until a secondfull deadline expires before raising. Collection succeeding is the normal path:
rabbitmq_debuginforuns itsrabbitmq-diagnosticssubprocesses throughPopen/communicatewithout checking their return codes, so it cannot fail evenagainst a broker that never started.
Measured against a real
rabbitmq:4.2.1-management-alpinecontainer whose brokernever boots, which is the condition the failing jobs are in: the loop runs 21
collections over 121.35s and spawns 63
rabbitmq-diagnosticsinvocations against analready wedged container. With the
break, one collection runs and the functionproceeds to the raise.
The
breakis the last statement of thetrybody, so a collection that does failstill retries to the deadline as before.
This changes the cost of the failure, not its verdict. The trailing
raise RuntimeError("Cannot wait RabbitMQ container")is unconditional, and the loop isreachable only once the readiness deadline has expired, so no run that passes today
executes this line. Verified: against a healthy container the waiter returns from the
first loop and the second is entered zero times.
wait_kafka_is_availableis the precedent: it collects diagnostics in atryplacedoutside its wait loop, so collection there happens once by construction.
wait_rabbitmq_to_startis the only waiter in the file that collects inside a deadlineloop.
I am not fixing the underlying failure here. The broker never boots and the artifacts
do not say why: the container never leaves
health: starting, docker's healthcheckreturns 69 on all 27 runs, and the broker emits no output. That belongs in a separate
report.
No related open issue found.
Occurrences and validation detail
Population, 120 days,
test_context_rawmatchingCannot wait RabbitMQ containerwith
test_status IN ('FAIL','ERROR'), split by raising caller: 18 occurrences reachit from
cluster.start()->wait_rabbitmq_to_start, spread over two shards(
Integration tests (arm_binary, distributed plan, 1/4)and2/4) and 17 distinctdays, including two runs with
head_ref = 'master'. One occurrence fails every testin the module because the fixture is module-scoped, so the 2-58 rows per occurrence
are collateral rather than independent flakes.
Three failing jobs show the same interval between the last readiness probe and the
RuntimeError(121.7s, 121.1s, 121.8s) withUnable to get logs from dockerabsent,so collection succeeded on every iteration there too.
Validation, all against real containers on this change:
what shows the
breakis inside thetryand not after itruffis clean. The file is notblack-formatted on master and I did not reformat it.The change is formatting-neutral, checked by normalizing the file with and without it:
the two normalized forms differ by exactly the added
breakline and are otherwisetoken-identical.
Version info
26.8.1.936(included in26.8and later)