Repository navigation
Read connection.unblocked before publishing, and optionally wait while blocked - #31
Merged
Merged
Conversation
The tests raise a real memory alarm with rabbitmqctl through the RabbitMQ service container, whose id CI now passes as RABBIT_CONTAINER, and skip when it is not set. - Without blocked_wait, a push on a blocked connection fails. - After the broker unblocks publishers, a push succeeds even without blocked_wait. Today the client keeps a stale blocked flag, because it never reads connection.unblocked, and every push fails. - With blocked_wait, a push waits for the broker to unblock, and fails once blocked_wait passes. - waitWhileBlocked() returns once unblocked, or false at its timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ocked php-amqplib refuses to publish on a connection flagged blocked, and only clears the flag when it reads connection.unblocked. Once a push throws, nothing reads the push connection, so the flag outlives the alarm. pushBatch() now calls waitWhileBlocked() before publishing. With the default blocked_wait of 0 it reads frames already received, which clears a stale flag. With blocked_wait above 0 it reads for up to that many seconds until the broker unblocks publishers. If the connection is still blocked, the publish fails with AMQPConnectionBlockedException as before. waitWhileBlocked($connectionMode, $timeout) is public for callers that publish on their own channel. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bajb
approved these changes
Nov 23, 2026
There was a problem hiding this comment.
🟡 Changes recommended
The change still contains critical wait() calls on AbstractConnection in both production and test code, causing undefined-method errors instead of processing connection state frames.
2 open issues
What changed in this PR
Updates the RabbitMQ provider to recover from stale blocked-connection state by reading broker frames before publishing and optionally waiting for the broker to unblock.
Changes:
- Added configurable
blocked_waithandling and a publicwaitWhileBlocked()helper. - Added RabbitMQ alarm integration tests covering blocked, recovery, waiting, and timeout behavior.
- Passed the RabbitMQ service container ID to PHPUnit in CI.
| File | Description |
|---|---|
| tests/Provider/AmqpTest.php | Adds integration tests for RabbitMQ blocked and unblocked publishing behavior. |
| src/Provider/Amqp/AmqpQueueProvider.php | Adds blocked-connection frame handling, optional waiting before publishing, and the public wait helper. |
| .github/workflows/unit-test.yml | Supplies the RabbitMQ service container ID to the PHPUnit test process. |
Review effort: Lite
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.

When RabbitMQ raises a memory or disk alarm it sends
connection.blocked, and php-amqplib then refuses every publish on that connection withAMQPConnectionBlockedException. It only clears the flag when it readsconnection.unblocked, but nothing reads from a push connection once publishing throws, so the flag outlives the alarm. In production a Fortifi retrieve worker threw 1,803 times in 90 seconds, nacking each message, for 55 seconds after the cluster cleared the alarm, until its daemon restarted.blocked_waitunset (default 0): fails withAMQPConnectionBlockedException, as before.blocked_wait> 0: waits up toblocked_waitseconds forconnection.unblocked, then publishes, or fails as before if still blocked.waitWhileBlocked($connectionMode, $timeout): waits up to$timeoutseconds and returns whether the connection is unblocked, for callers that publish on their own channel.Test plan
RABBIT_CONTAINER, now passed to PHPUnit) and skip without it.Connection is blocked due to low resources, a push withblocked_waitthrew after 0.0001s, andwaitWhileBlocked()did not exist. With the fix, all 42 jobs pass with every test run (PHP 7.4–8.4 × RabbitMQ 3.10–4.2).🤖 Generated with Claude Code