Skip to content

Make the queue-removal check in test_rabbitmq_drop_table_properly precise - #114269

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:rabbitmq-drop-table-queue-poll
Aug 12, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:rabbitmq-drop-table-queue-poll

Conversation

@groeneai

@groeneai groeneai commented Aug 11, 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

test_rabbitmq_drop_table_properly asserts the broker queue is gone after DROP TABLE, and
intermittently fails (7 hits / 4 PRs in 180 days for this assertion, 0 on master, all on slow
configurations). This PR makes the assertion precise. It does not fix the leak behind those
failures, and it does not hide it either.

The assertion wrapped the passive declare in except Exception: exists = False, reading any
failure as "queue gone", so a dead connection or a non-404 channel close passed while the queue
was still there. It now requires reply_code == 404, and time.sleep(30) becomes a bounded poll
with the same 30 s budget, so a passing run finishes in milliseconds. The budget is deliberately
not widened, which would accept a real leak, and not cut to one immediate check, which would
reject the legitimately late delete the original accepted.

The failures are a real engine defect, visible in the server logs of two of those runs: the
broker refuses the delete with PRECONDITION_FAILED - queue '...' in use, 1 ms into a 1.5 ms
DROP. closeConnections() issues channel->close() without awaiting close-ok
(RabbitMQConsumer.cpp:50-54, from StorageRabbitMQ.cpp:1012); cleanupRabbitMQ() then issues
removeQueue(queue, AMQP::ifunused) on a different channel (:1086). AMQP 0-9-1 orders method
completion per channel, not across channels, so the table's own consumer can still be attached.
The queue is AMQP::durable with autodelete deliberately disallowed (:772-774), so it leaks
permanently. Awaiting close-ok fixes this path but stalls every DROP of a table that has
nacked, because basic.nack is misclassified as synchronous in contrib/AMQP-CPP and the close
frame is then never sent. That is the prerequisite, so the leak stands and this test keeps
catching it.

Also pre-existing: with rabbitmq_num_queues > 1 the delete loop stops after the first
delete-ok (StorageRabbitMQ.cpp:1092), leaving deletes 2..N unconfirmed.

Version info

  • Merged into: 26.8.1.1228 (included in 26.8 and later)

The final existence check used a bare time.sleep(30) plus a one-shot passive
declare, while the data check ~15 lines earlier already polls with
DEFAULT_TIMEOUT_SEC. Replace it with the same bounded-poll idiom.

pika closes the channel when a passive declare fails, so the channel is
reopened on every attempt; otherwise the second attempt would raise for the
wrong reason and the assertion would pass vacuously. Only a 404 counts as
"queue gone" - any other channel close now fails the test loudly.

This is a robustness/runtime change, not a fix for the underlying leak: the
broker's answer to queue.delete arrives inside the DROP (cleanupRabbitMQ blocks
up to BLOCKING_LOOP_TIMEOUT_MS), so it is already settled before the old sleep
began, and the poll cannot mask it. The passing case drops from a fixed 30s to
under a second.
Follow-up to the previous commit, which polled to DEFAULT_TIMEOUT_SEC (60s).

DROP TABLE is synchronous down to the broker: InterpreterDropQuery calls
flushAndShutdown(true), and cleanupRabbitMQ() blocks on
startBlockingLoopWithTimeout(BLOCKING_LOOP_TIMEOUT_MS = 30000). The broker's
answer to queue.delete is therefore already settled before any post-DROP wait
begins, so the wait is slack either way and 60s only widens what the assertion
accepts. It must not be narrowed to a single immediate declare either: on the
loop-timeout path removeQueue has already sent the QueueDeleteFrame and only
our callbacks are abandoned, so the broker may still delete the queue slightly
later, and the original test accepted that. 30s reproduces the original
acceptance window exactly.

The substantive change is in the previous commit's 404 requirement, not in the
waiting: the old form treated any exception as "queue gone", so a dead
connection or a non-404 channel close passed vacuously. Correcting the earlier
commit message: the poll cannot mask the permanent leak paths, but a wider
window would have masked a late broker-side delete.

One pika channel is now reused across attempts. A successful passive declare
leaves the channel usable, and the 404 path breaks out immediately, so the
channel is never used after the broker closes it.
@groeneai

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

Two independent reviews of this change plus one adversarial gate pass. Findings below, with
verdicts. The code was clean in both rounds; the blockers were about the truth of claims in the
description, which is checkable from public URLs.

# Finding Verdict
❌ "Every CI log from the observed failures has expired." Agreed, wrong, corrected. Both job bundles are live: PR 107615 job.log 200 / 406,613 B and logs.tar.gz 200 / 604,866,903 B; PR 108569 job.log 200 / 416,233 B and logs.tar.gz 200 / 547,479,348 B. The claim is gone from the description.
❌ "The mechanism behind the failure is unestablished." Agreed, wrong, corrected. It is in the server logs of two runs. In PR 108569 the queue has exactly four lifetime lines, ending 10:00:12.012824 <Error> Failed to delete queue ... PRECONDITION_FAILED - queue '...' in vhost '/' in use, which is the onError branch of removeQueue(queue, AMQP::ifunused). Timing: Started blocking loop at .011880, refusal at .012824, whole DROP Processed in 0.001795469 sec - so the refusal is immediate and none of the 30 s cleanup timeout is consumed. Three controls: Successfully deleted queue appears 59 times for sibling queues in the same file and 0 times for this one (so the line is greppable at this log level and its absence means something); Timed out waiting for queue cleanup 0 times; nack/reject/requeue for this test 0 times, so the consumer channel is not wedged. The description now states the mechanism, states that this PR does not fix it, and says what it is sequenced behind.
⚠️ Dropping the per-attempt channel reopen could make a later declare raise for the wrong reason and pass vacuously. Verified safe. A successful passive declare leaves the channel open, and the 404 path breaks out immediately, so the channel is never used after the broker closes it. Measured over 10 consecutive declares on one channel followed by a correct 404, and the 50-run loop records exactly 50 Channel.Close (404) receipts - one per run.
⚠️ The new except pika.exceptions.ChannelClosedByBroker may be unreachable on the version CI pins. Verified reachable on the pinned version. CI pins pika==1.3.2 (the host has 1.4.2). On 1.3.2: pika.exceptions resolves under a bare import pika, ChannelClosedByBroker(404, ...).reply_code == 404, and BlockingChannel._flush_output raises the closing reason.
⚠️ A bounded poll could hide a real leak, or reject a legitimately slow delete. Pinned from both sides, measured. Never-deleted fails at 30.16 s, so a real leak is still caught; a delete at T+5 s passes at 5.02 s, which the original 30 s sleep also accepted. Widening to 60 s would have accepted the first case; a single immediate check would have rejected the second.
💡 Are there sibling assertions with the same vacuous shape? No. passive=True appears in one file at two sites: this one, and a positive assert exists that cannot pass vacuously. No other assert not exists after a passive declare anywhere in the integration suite.
💡 CIDB figures in the description. Confirmed, with a caveat for anyone rechecking. The stored test_name is test_storage_rabbitmq/test.py::test_rabbitmq_drop_table_properly, so a bare-name query returns zero rows. Classifying all 50 failures of this test over 180 days gives 7 hits of this assertion across 4 pull requests and none on master; the remaining rows are the unrelated container-startup signature.

Not raised as follow-up work: rabbitmq_num_queues > 1 leaves deletes 2..N unconfirmed
(mentioned in the description). It is pre-existing, it is not this failure, and I have not run it.

Session id: cron:clickhouse-review-slot-10:20260811-042400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? YES for what this changes (the oracle): 6/6 deterministic broker-only arms, plus an end-to-end arm on a table that reliably leaks its queue (8/8). The CI failure itself is rare (7 hits / 4 PRs in 180 days) and was not reproduced locally; it did not need to be, because two of those runs recorded the mechanism in their server logs (row b).
b Root cause explained? YES for both defects. Oracle defect (fixed here): except Exception: exists = False treats any declare failure as "queue gone", so a dead connection or a non-404 close passes while the queue is present. Engine defect (NOT fixed here, described in the PR body): the broker refuses the delete with PRECONDITION_FAILED ... in use, read from the logs.tar.gz bundles of PRs 107615 and 108569 - a 4-line queue lifetime ending in that refusal and no Successfully deleted queue line, against 59 such lines for sibling queues in the same file as a positive control.
c Fix matches root cause? YES. The change tightens the check; it does not add patience. The acceptance window is held at exactly the original 30 s, so this is not the longer-sleep band-aid.
d Test intent preserved / new tests added? Preserved and strengthened. Same assertion (the queue is gone), now unable to pass for the wrong reason. Nothing removed, no bound widened, no dataset reduced. Test-only change, so no separate regression test.
e Both directions demonstrated? YES. On a dead connection, and on a real 406 close with the queue still present, the old form passes and the new form fails. Against a genuinely leaked queue the new form fails; against a deleted queue it passes in 0.001 s.
f Fix is general across code paths? The defect is confined to this one assertion. I grepped the module for the same except Exception + assert not shape: the only other passive-declare sites are positive assert exists checks, which cannot pass vacuously. No sibling to fix.
g Fix generalizes across inputs (params/datatypes/wrappers)? Covered for every failure shape the check can observe: queue present, queue absent, dead connection, non-404 broker close, delayed delete, never deleted. Not a typed-value change, so the Nullable/LowCardinality matrix does not apply.
h Backward compatible? (maintainer-approved exception only) YES, trivially. Integration test only: no setting, no format, no SettingsChangesHistory.cpp.
i Invariants and contracts preserved? YES. The invariant at risk is the pika channel contract, since one channel is now reused: a successful passive declare leaves the channel usable (verified over 10 consecutive declares, followed by a correct 404 on the same channel), and no path continues past a broker close. No no-parallel needed: no new shared broker or filesystem state, and names still come from the existing per-test fixtures.

Session id: cron:clickhouse-impl-slot-6:20260811-040800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @kssenii, could you review this? It is a test-only change: the queue-removal check in test_rabbitmq_drop_table_properly wrapped its passive declare in except Exception, so any failure (a dead connection, a non-404 channel close) read as "queue gone"; it now requires reply_code 404 and polls within the same 30 second window instead of sleeping through it.

@PedroTadim

Copy link
Copy Markdown
Member

cc @pamarcos

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fbc2433]

Summary: ✅


AI Review

Summary

This PR tightens test_rabbitmq_drop_table_properly so the post-DROP TABLE queue probe only treats RabbitMQ 404 as successful removal and preserves the original 30 second acceptance window by clamping each sleep to the remaining budget. I did not find a remaining correctness, test-contract, or PR-metadata issue in the current diff.

Final Verdict

✅ No blocking issues found.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 12, 2026
The deadline was tested only after a successful passive declare, and the loop then
always slept a full 0.5 s, so the last declare could land up to one sleep interval
past the 30 s deadline. Whether it did depended on where the deadline fell relative
to the declare grid: with the deadline exactly on a multiple of the interval the
window was exact, and anywhere else it was widened by up to 0.5 s. A queue deleted
in that tail was accepted, which the fixed sleep(30) it replaced would have failed.

Sleeping only up to the remaining budget puts the last declare at the deadline, so
the accepted window is exactly queue_removal_timeout_sec. Computing `remaining` once
and reusing it for both the deadline test and the sleep means the sleep argument
cannot go negative, so no clamp at zero is needed.

Measured against the loop extracted verbatim from the test, sweeping the deadline
across a whole sleep interval: worst-case overshoot 0.45 s before, 0.0002 s after.
On a real broker with rabbitmqctl as independent ground truth, a delete 0.1 s past a
3.05 s budget is now rejected at 3.051 s, while a delete inside the budget and a
still-present queue keep their previous verdicts. Identical on pika 1.3.2, which CI
pins, and on 1.4.2.
@groeneai

Copy link
Copy Markdown
Collaborator Author

The finding is correct, and it is fixed in fbc2433.

The deadline was tested only after a successful passive declare and the loop then always slept a
full 0.5 s, so the last declare could land up to one interval past the 30 s deadline. Whether it
actually did depended on where the deadline fell relative to the declare grid, which is why the
first check I ran did not show it: with the deadline exactly on a multiple of 0.5 s the window is
exact, and anywhere else it is widened. Sweeping the deadline across a whole interval against the
loop extracted verbatim from the test, worst-case overshoot was 0.45 s before the change and
0.0002 s after.

I took the second of the two suggested shapes, computing the remaining budget once and reusing it
for both the deadline test and the sleep:

remaining = deadline - time.monotonic()
if remaining <= 0:
    pytest.fail(...)
time.sleep(min(0.5, remaining))

This reaches the sleep only when remaining > 0, so the argument cannot go negative and no clamp
at zero is needed (time.sleep raises ValueError on a negative argument, so that mattered).

Verified on a real broker with rabbitmqctl as ground truth, independent of the assertion under
test: a delete 0.1 s past a 3.05 s budget is now rejected at 3.051 s; a delete inside the budget
is still accepted; a queue that is never deleted still fails; a non-404 close still fails rather
than reading as "gone". Same results on pika 1.3.2, which CI pins, and on 1.4.2. The changed test
is 50/50 green with 50 real 404 receipts and no timeouts.

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fbc2433e2 with master 48b91073f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 86e654b84; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 691.40 MiB 688.19 MiB -3.21 MiB (-0.46%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

63 translation units recompiled, 226 s compile time in total, 63 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - fbc2433e2fca7c7ba0b04b57adc4c5c4b1b39e9d

CI is fully finished on this head and there are no failing checks.

Praktika report: 176 leaves, 0 dropped jobs, 15 OK / 161 skipped, top-level OK. The high skip
count is expected for a test-only diff (Not affected by the changed files and not required x94,
no build-affecting changes x25, none of the changed tests apply x20). The integration suites
that cover the changed file did run: Integration tests (amd_msan, *), (amd_tsan, *),
(arm_binary, distributed plan, *) all green.

Check / test Reason Owner / fixing PR
(none) - -

Session id: cron:our-pr-ci-monitor:20260812-053000

@PedroTadim PedroTadim self-assigned this Aug 12, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 12, 2026
Merged via the queue into ClickHouse:master with commit 48f2d64 Aug 12, 2026
181 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
@groeneai groeneai added the groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet label Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet 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