-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] return empty envelopes when RetryableException occurs #32979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Messenger\Transport\Doctrine; | ||
|
||
use Doctrine\DBAL\DBALException; | ||
use Doctrine\DBAL\Exception\RetryableException; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Exception\LogicException; | ||
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException; | ||
|
@@ -30,6 +31,8 @@ | |
*/ | ||
class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface, ListableReceiverInterface | ||
{ | ||
private const MAX_RETRIES = 3; | ||
private $retryingSafetyCounter = 0; | ||
private $connection; | ||
private $serializer; | ||
|
||
|
@@ -46,6 +49,17 @@ public function get(): iterable | |
{ | ||
try { | ||
$doctrineEnvelope = $this->connection->get(); | ||
$this->retryingSafetyCounter = 0; // reset counter | ||
} catch (RetryableException $exception) { | ||
// Do nothing when RetryableException occurs less than "MAX_RETRIES" | ||
// as it will likely be resolved on the next call to get() | ||
// Problem with concurrent consumers and database deadlocks | ||
if (++$this->retryingSafetyCounter >= self::MAX_RETRIES) { | ||
$this->retryingSafetyCounter = 0; // reset counter | ||
throw new TransportException($exception->getMessage(), 0, $exception); | ||
surikman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be better to retry "internally" (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not seem better to me. This way we can use the delay that is added after the get which is what we want with a deadlock/timeout problem. |
||
} catch (DBALException $exception) { | ||
throw new TransportException($exception->getMessage(), 0, $exception); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.