[Messenger][Amqp] Fix polling an empty queue counting as a message in flight - #66039
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Connection::get()checks the result ofAMQPQueue::get()withfalse !== $message. That was right for ext-amqp 1.x. ext-amqp 2.x returnsnullwhen the queue is empty, and its stub declarespublic 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
inFlightMessagesand returnsnull. Onlyack()andnack()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 when0 === $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
AMQPEnvelopeis always truthy,falseis not andnullis not.