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

Skip to content

Commit 8c77699

Browse files
committed
[Messenger] widen retry catch to \AMQPException, rename helper
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.
1 parent fcd7a4a commit 8c77699

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Transport/AmqpExt/Connection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function publish(string $body, array $headers = [], int $delayInMs = 0, A
187187
{
188188
$this->clearWhenDisconnected();
189189

190-
$this->withConnectionExceptionRetry(function () use ($body, $headers, $delayInMs, $amqpStamp) {
190+
$this->withAmqpExceptionRetry(function () use ($body, $headers, $delayInMs, $amqpStamp) {
191191
if (0 !== $delayInMs) {
192192
$this->publishWithDelay($body, $headers, $delayInMs, $amqpStamp);
193193

@@ -456,15 +456,15 @@ private function clear(): void
456456
$this->amqpDelayExchange = null;
457457
}
458458

459-
private function withConnectionExceptionRetry(callable $callable): void
459+
private function withAmqpExceptionRetry(callable $callable): void
460460
{
461461
$maxRetries = 3;
462462
$retries = 0;
463463

464464
retry:
465465
try {
466466
$callable();
467-
} catch (\AMQPConnectionException $e) {
467+
} catch (\AMQPException $e) {
468468
if (++$retries <= $maxRetries) {
469469
$this->clear();
470470

0 commit comments

Comments
 (0)