Skip to content

Fix flaky test_rabbitmq_reconnect_drops_stale_deliveries: do not wait 300 s for a hung rabbitmqctl call - #126746

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:rabbitmq-reconnect-test-bounded-list-queues
Oct 31, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:rabbitmq-reconnect-test-bounded-list-queues

Conversation

@groeneai

@groeneai groeneai commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

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):

...

Description

Related: #125105 (added the test)
Related: #126206 (fix requested there)
Related: #126642 (fix requested there)

On arm a new rabbitmqctl process occasionally never returns while the broker stays healthy (29/29 healthchecks), and the test waited 300 s in Integration tests (arm_binary, 2/4): list_queues (#126206, #126013), close_all_connections (master, #127389, #126642).

list_queues is now asked only once the row count is stable for 3 s (one call per run, not 15-20), abandoned after 30 s and asked again under the 180 s deadline.

The close never reached the broker. A retry does not fit (the drop must happen within ~9 s, and an abandoned CLI keeps running in the container), so the close goes through the management API (DELETE /api/connections/username/root): the same rabbit_networking:close_connection, no CLI process. list_queues keeps the CLI: it reads live counters, the API 5 s samples.

The hang does not reproduce on x86, so I injected sleep 600: unfixed, the test fails after 300 s with the CI error for either call; fixed, a hung list_queues is abandoned after 30 s and it passes. Without the DELETE it fails waiting for the reconnect. 50/50 runs pass; the pre-#125105 binary still fails on duplicates (8300-9500 > 200).


Workflow [PR]
Sync PR [sync-upstream/pr/126746]

Version info

  • Merged into: 26.11.1.963-master (included in 26.11 and later)

…_drops_stale_deliveries

The drain loop started a new `rabbitmqctl list_queues` (an Erlang CLI VM via
`docker exec`) on every iteration, 15-22 times per run on arm, and waited up to
the harness default of 300 s for each without a retry. In 3 runs of
`Integration tests (arm_binary, 2/4)` on 2026-10-19 one call never returned and
printed nothing, while ClickHouse had inserted all 10100 rows and the broker
passed its `rabbitmq-diagnostics ping` healthcheck 29/29 times in that window,
so the loop's own 180 s deadline was never checked.

Ask the broker only once the row count has been stable for 3 s (same exit
condition, about one call per run), and abandon a call after 30 s and ask again
under the existing deadline. Only a timeout is treated as "not drained yet".
`close_all_connections` is unchanged: a retry could force a second reconnect.

Validated with an injected never-returning call (unfixed: fails after 300 s with
the CI error; fixed: passes 2/2 with one abandoned call), 50/50 normal runs, and
the pre-ClickHouse#125105 binary, which still fails on the duplicates bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ A timed-out docker exec leaves the hung rabbitmqctl running in the broker container, so retries could accumulate leaked VMs (test.py:4042) DISAGREE The unfixed 300 s path leaked the same process: the timeout wraps only the host-side docker exec in both versions (helpers/cluster.py:2876-2898, unchanged). Piling up needs the retry to hang too, but during each of the 3 CI hangs the container healthcheck rabbitmq-diagnostics -q ping (also a fresh CLI VM) passed 29 of 29 times in about 0.4 s, so one hang still leaks one VM. A persistent hang fails at the 180 s deadline either way.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-8:20261019-162000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Of the failure mode, yes: the arm-only CLI hang does not reproduce on x86, so the first list_queues call is replaced locally by sleep 600 in the rabbitmq container (same exec_in_container path). The unfixed test then fails 1/1 with the CI error, timed out after 300 seconds from queue_drained.
b Root cause explained? The drain loop started a new rabbitmqctl on every iteration (about 15-20 per run on arm) and waited up to 300 s for each with no retry, so one call that never returned failed the test while ClickHouse and the broker were healthy and the loop's own 180 s deadline was never checked.
c Fix matches root cause? Yes: the CLI is asked only after the row count is stable for 3 s (about one call per run), and a call is abandoned after 30 s and asked again under the existing deadline. No bound widened, no tag added, no data reduced.
d Test intent preserved / new tests added? Exit condition unchanged (0 ready, 0 unacked, rows stable 3 s); the new path only returns "not drained yet". With the binary from before #125105 the test still fails on 8300 duplicates (2/2). Test-only change.
e Both directions demonstrated? Injected hang: unfixed test fails (CI error), fixed test passes 2/2 with one abandoned call. 50/50 normal runs pass with one rabbitmqctl call each.
f Fix is general across code paths? The only other rabbitmqctl call, close_all_connections (once per run), is left as is on purpose: retrying it after a timeout could force a second reconnect and extra legitimate duplicates. No other test calls rabbitmqctl.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test timing fix); runs used the harness random settings.
h Backward compatible? (maintainer-approved exception only) N/A, test-only.
i Invariants and contracts preserved? Any error other than a timeout still fails the test; the loop stays bounded by 180 s; the final assertions are unchanged.

Session id: cron:clickhouse-impl-slot-4:20261019-153000

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin, could you review this and add the can be tested label so CI runs? The RabbitMQ reconnect test now asks rabbitmqctl list_queues only once the row count is stable, and abandons a call that hangs after 30 s and asks again under its existing 180 s deadline, instead of waiting the harness default of 300 s on one call.

@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9c18fa2]

Summary: ✅


AI Review

Summary

The PR reduces CLI calls in test_rabbitmq_reconnect_drops_stale_deliveries, bounds list_queues calls to 30 seconds, and closes connections through RabbitMQ's management API. No actionable findings at commit 9c18fa2e31f5054ef218611eae8b7b9341ca87f9.

Missing context / blind spots
  • ⚠️ The latest integration jobs are pending, and I did not rerun the Docker suite locally. Regression evidence comes from the author's reported fault-injection runs, 50 successful runs, and checks that the original buggy binary still fails. A completed targeted ARM CI run would provide independent confirmation.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 19, 2026
@antaljanosbenjamin antaljanosbenjamin self-assigned this Oct 20, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 21, 2026
…es without rabbitmqctl

`rabbitmqctl close_all_connections test` timed out after 300 s in 3 runs of
`Integration tests (arm_binary, 2/4)` (master 524a0c2, ClickHouse#127389, ClickHouse#126642). The
close never reached the broker: no `Closing connection ... because "test"` line
in its log, and ClickHouse's AMQP connection stayed open for 5 minutes until the
test dropped the database. The broker passed its `rabbitmq-diagnostics ping`
healthcheck 29/29 times in each window, so a new CLI process again never got to
its RPC, like the `list_queues` call before.

Bounding the call and asking again does not fit here: the drop must happen while
most of the backlog is still queued (`view_rows() < messages_num // 2`), which
leaves about 9 s after the 500-row trigger at ~490 rows/s, and a timed-out
`docker exec` leaves the CLI running in the container, where a late close would
force a second reconnect.

Close through the management API instead:
`DELETE /api/connections/username/root` with `X-Reason: test` reaches the same
`rabbit_networking:close_connection(Pid, "test")` for every connection of the
broker's only user, synchronously before the 204 reply, and starts no CLI process.

Validated: an injected never-returning close fails the unfixed test after 300 s
with the CI error; without the DELETE the test fails waiting for the reconnect;
the pre-ClickHouse#125105 binary still fails on the duplicates bound (9500, 9400); 50/50
runs pass with `204` (p50 0.1 s) and ClickHouse logs `CONNECTION_FORCED - test`
then `Connection restored`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Fix flaky test_rabbitmq_reconnect_drops_stale_deliveries: do not wait 300 s for one rabbitmqctl list_queues call Fix flaky test_rabbitmq_reconnect_drops_stale_deliveries: do not wait 300 s for a hung rabbitmqctl call Oct 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log, close_all_connections commit (click to expand)

Pre-publication review of 9c18fa2e by an independent model (engine: codex; 2 delta passes against 90f61387, 1 finding each).

# Sev Finding Verdict Evidence / action
1 💡 Related references were short #N on one line, not full URLs one per line AGREE Fixed in the PR description; the second pass did not raise it again.
2 💡 The commit messages do not carry the full CI report URLs AGREE, not changed The first commit is already pushed and is not rewritten; the PR description links all five failing jobs and their PRs.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20261028-152500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate, `close_all_connections` commit (click to expand)
# Question Answer
a Deterministic repro? Of the failure mode: the arm-only CLI hang does not reproduce on x86, so the close was replaced locally by sleep 600 in the rabbitmq container. The unfixed test fails 1/1 after 300 s with the CI error, raised at the close line.
b Root cause explained? The close ran a new rabbitmqctl process via docker exec; on arm it occasionally never reaches its RPC (no Closing connection line in the broker log, ClickHouse stayed connected) and the harness waits 300 s, while the broker passes its healthcheck.
c Fix matches root cause? Yes: the close goes through the management API (DELETE /api/connections/username/root, reason test), the same rabbit_networking:close_connection, with no CLI process. No bound widened, no retry, no try/except.
d Test intent preserved / new tests added? Without the DELETE the test fails waiting for Connection restored; with the binary from before #125105 it still fails on the duplicates bound (9500 and 9400 > 200). Test-only change.
e Both directions demonstrated? Injected hang: unfixed fails with the CI error; fixed starts no CLI process for the close and passes 50/50 (DELETE 204 every run, p50 0.1 s).
f Fix is general across code paths? list_queues is bounded by the previous commit; the harness startup probe is already bounded and retried; no other test in the module calls rabbitmqctl.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test harness interaction); runs used the harness random settings.
h Backward compatible? (maintainer-approved exception only) N/A, test-only.
i Invariants and contracts preserved? The close completes before the 204 reply (broker log, then CONNECTION_FORCED - test in ClickHouse, then 204); any non-2xx or a 30 s timeout fails the test at that line; every assertion after it is unchanged.

Session id: cron:clickhouse-impl-slot-4:20261028-143600

def queue_drained():
out = rabbitmqctl("-q", "list_queues", "name", "messages_ready", "messages_unacknowledged")
nonlocal abandoned_calls
# A rabbitmqctl call occasionally never returns, so give up on it and ask again.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why it doesn't return?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't know the root cause. It doesn't reproduce on x86, and the CI artifacts have nothing from inside the stuck process. Here is what the six failed arm_binary runs I looked at show:

  • In each run exactly one rabbitmqctl process never exits. The other calls in the same run finish in about 0.5 s.
  • The broker is fine the whole time. The container healthcheck rabbitmq-diagnostics -q ping, which is also a fresh CLI process through docker exec, passed 29 of 29 times inside each 300 s window. rabbit.log shows nothing unusual, and ClickHouse consumed the whole queue.
  • The process gets stuck before it does any work. The hung close_all_connections printed nothing at all, not even its Closing all connections in vhost /, reason: test... banner. The CLI prints that banner after it starts Erlang distribution and checks rabbit:is_running on the node, and before the close RPC (rabbitmqctl.ex). The broker never logged Closing connection ... because "test" either. The hung list_queues ran for 300 s without an error, so it never reached the 60 s timeout of its listing RPC.

So, at least for the close, the hang is in the CLI's own startup: Erlang VM boot, the distribution start, or the rabbit:is_running check. The artifacts can't tell which one. The broker's own Erlang node in this image has a similar boot hang, almost always on arm_binary, which is why wait_rabbitmq_to_start recreates the container since 27ebf5a.

That's why this PR works around the hang instead of fixing it. If you want the root cause, I can capture the stuck process when a call times out (an in-container ps plus an Erlang crash dump via kill -USR1).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While we can't answer, we still have no other option. As long as the test is still ok, this is good to merge.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 31, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 31, 2026
Merged via the queue into ClickHouse:master with commit b3b8c37 Oct 31, 2026
179 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 31, 2026
@clickhouse-gh clickhouse-gh Bot added comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). 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.

4 participants