Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger][Amqp] Fix polling an empty queue counting as a message in flight - #66039

Merged
nicolas-grekas merged 1 commit into
symfony:7.4from
nicolas-grekas:amqp-get-empty-queue
Sep 13, 2026
Merged

[Messenger][Amqp] Fix polling an empty queue counting as a message in flight#66039
nicolas-grekas merged 1 commit into
symfony:7.4from
nicolas-grekas:amqp-get-empty-queue

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Member
Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

Connection::get() checks the result of AMQPQueue::get() with false !== $message. That was right for ext-amqp 1.x. ext-amqp 2.x returns null when the queue is empty, and its stub declares public function get(?int $flags = null): ?AMQPEnvelope.

So on ext-amqp 2.x, every poll of an empty queue takes the "got a message" branch: it increments inFlightMessages and returns null. Only ack() and nack() decrement that counter, and neither runs for a message that was never received, so the counter grows by one per idle poll.

The counter guards the heartbeat reconnect in channel(), which disconnects only when 0 === $this->inFlightMessages. After the first poll of an empty queue that condition is never true again, so the heartbeat-driven disconnect never happens any more. Any worker that has seen an empty queue once keeps a connection the broker may have dropped.

A truthy check covers both cases, since an AMQPEnvelope is always truthy, false is not and null is not.

… flight

ext-amqp 2.x returns null from AMQPQueue::get() when the queue is empty, while
1.x returned false. The "false !== $message" check therefore took the "got a
message" branch on every idle poll and incremented the in-flight counter, which
only ack() and nack() ever decrement. The counter then never went back to zero,
so the heartbeat guard in channel(), which reconnects only when no message is in
flight, stopped firing for good.
@carsonbot carsonbot added this to the 7.4 milestone Sep 13, 2026
@nicolas-grekas
nicolas-grekas merged commit 7592415 into symfony:7.4 Sep 13, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants