[Messenger] widen retry catch to \AMQPException#2
Merged
modess merged 1 commit intoApr 10, 2026
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Production logs show bare \AMQPException (not \AMQPConnectionException) thrown from ext-amqp C code during declareExchange() on fresh connections. The C extension doesn't always promote SSL errors to AMQPConnectionException — unmapped library_error codes fall to the default branch in php_amqp_zend_throw_exception(). Widen the catch from \AMQPConnectionException to \AMQPException so the retry wrapper catches all ext-amqp failures during publish. Rename the helper from withConnectionExceptionRetry to withAmqpExceptionRetry to match the new behavior. Safe: clear() drops all cached state between retries, and max 3 retries bounds the cost. Worst case is 3 extra reconnection attempts.
6b2edd3 to
8c77699
Compare
modess
approved these changes
Apr 10, 2026
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.
Problem
PR #1 backported
withConnectionExceptionRetry()from symfony/symfony#54167, catching\AMQPConnectionExceptionaroundpublish(). After deploying to production, the errors continued unchanged.Production logs show bare
\AMQPException— not\AMQPConnectionException— thrown from ext-amqp's C code duringdeclareExchange():The retry wrapper caught
\AMQPConnectionExceptiononly, so it never fired.Why bare
\AMQPException?ext-amqp's C code has a central
php_amqp_zend_throw_exception()that mapsAMQP_STATUS_SSL_ERROR→AMQPConnectionException. ButdeclareExchange()usesphp_amqp_zend_throw_exception_short()which may not have the same override — unmappedlibrary_errorcodes fall to thedefaultbranch → bareAMQPException.We confirmed the exception originates from C code (not PHP) via
Exception::getFile()/getLine()semantics: C extension exceptions report the PHP call site that invoked the C function. Line 366 =declareExchange()call site, not the PHP-levelchannel()rethrow at line 397 (which would report line 397).Root cause was also misdiagnosed
PR #1 assumed 350s NLB idle TCP timeout killing stale connections. Investigation proved this wrong for HTTP publishers:
public/index.phpcreatesnew Kernel()per request — no service persistence across FPM requestsThe actual failure: intermittent TLS errors on fresh connections during
declareExchange().Fix
Two-line change:
catch (\AMQPConnectionException $e)→catch (\AMQPException $e)— catches all ext-amqp exceptions during publish, including bareAMQPExceptionfromdeclareExchange()withConnectionExceptionRetry→withAmqpExceptionRetry— name matches new behaviorThat's it.
+3 / -3lines. No other behavioral changes.Why not also fix the channel() rethrow?
channel()catches\AMQPConnectionExceptionand rethrows as\AMQPException(stock Symfony behavior). With the wider catch on\AMQPException, this is already handled — both types are caught. Changing the rethrow type would diverge from stock Symfony for zero practical benefit.Why not move clearWhenDisconnected() inside the retry?
Codex review flagged that
clearWhenDisconnected()runs before the retry wrapper, meaning aconnect()failure there is unretried. True, but the retry wrapper already handles stale connections via catch +clear()—clearWhenDisconnected()is just an optimization to avoid wasting one retry attempt. With 3 retries available, this isn't worth the code churn.Safety
clear()drops all cached state (channel, queues, exchange, delay exchange) between retries. Max 3 retries bounds the cost. Worst case: 3 extra reconnection attempts before the final exception propagates.Divergence from upstream
Upstream symfony/symfony#54167 catches only
\AMQPConnectionException. Upstream has the same bug — their tests mock at the exchange level and never exercise real C code exception paths.Consumer
sweetspotio/sweetspot-api-platform will bump
composer.lockafter merge.