-
-
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
[Messenger] return empty envelopes when RetryableException occurs #32979
Conversation
b94e988
to
a5693f5
Compare
8189b65
to
864b51d
Compare
src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a safety counter to catch (RetryableException $exception)
so when it's happens like 3 times in a row, we rethrow. Otherwise a permanent deadlock or misconfiguration of timeouts might be invisible as you would always just hide the exception.
@Tobion Thanks. I implemented safety counter as you described. |
ca322e5
to
20cddc3
Compare
src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
Outdated
Show resolved
Hide resolved
877c401
to
8e69051
Compare
src/Symfony/Component/Messenger/Tests/Transport/Doctrine/DoctrineReceiverTest.php
Show resolved
Hide resolved
8e69051
to
c64f5ae
Compare
throw new TransportException($exception->getMessage(), 0, $exception); | ||
} | ||
|
||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to retry "internally" (i.e. return $this->get()
) instead of returning this empty array? Otherwise, in the event of using multiple transports, the worker might start consuming lower priority messages, which would make no sense. Similar with whatever might decorate this receiver... it would "see" an empty array while actually, it was an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sroze we need your approval here
Thank you @surikman. |
c64f5ae
to
9add32a
Compare
… occurs (surikman) This PR was squashed before being merged into the 4.3 branch (closes #32979). Discussion ---------- [Messenger] return empty envelopes when RetryableException occurs | Q | A | ------------- | --- | Branch? | 3.4 or 4.3 for bug fixes <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | License | MIT | ~~Doc PR~~ | ~~symfony/symfony-docs#12109~~ <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against branch 4.4. - Legacy code removals go to the master branch. --> Problem occurs when you are using more than 1 worker with Doctrine Transport. `Symfony\Component\Messenger\Transport\Doctrine\Connection::get` does a query `SELECT ... FOR UPDATE` and this locking query could lock table and workers stops. But using locks can result in dead locks or lock timeouts. Doctrine renders these SQL errors as RetryableExceptions. These exceptions are often normal if you are in a high concurrency environment. They can happen very often and your application should handle them properly. Commits ------- 9add32a [Messenger] return empty envelopes when RetryableException occurs
Doc PRsymfony/symfony-docs#12109Problem occurs when you are using more than 1 worker with Doctrine Transport.
Symfony\Component\Messenger\Transport\Doctrine\Connection::get
does a querySELECT ... FOR UPDATE
and this locking query could lock table and workers stops. But using locks can result in dead locks or lock timeouts. Doctrine renders these SQL errors as RetryableExceptions. These exceptions are often normal if you are in a high concurrency environment. They can happen very often and your application should handle them properly.