Skip to content

[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

Merged

Conversation

surikman
Copy link
Contributor

@surikman surikman commented Aug 6, 2019

Q A
Branch? 3.4 or 4.3 for bug fixes
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
License MIT
Doc PR symfony/symfony-docs#12109

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.

@surikman surikman force-pushed the messenger-doctrine-use-retryable-exception branch from b94e988 to a5693f5 Compare August 6, 2019 08:29
@nicolas-grekas nicolas-grekas added this to the 4.3 milestone Aug 6, 2019
@surikman surikman requested a review from sroze as a code owner August 6, 2019 16:54
@surikman surikman force-pushed the messenger-doctrine-use-retryable-exception branch from 8189b65 to 864b51d Compare August 6, 2019 16:56
Copy link
Contributor

@Tobion Tobion left a 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.

@surikman
Copy link
Contributor Author

surikman commented Aug 7, 2019

@Tobion Thanks. I implemented safety counter as you described.

@surikman surikman force-pushed the messenger-doctrine-use-retryable-exception branch from ca322e5 to 20cddc3 Compare August 7, 2019 07:49
@surikman surikman force-pushed the messenger-doctrine-use-retryable-exception branch from 877c401 to 8e69051 Compare August 12, 2019 06:46
@surikman surikman force-pushed the messenger-doctrine-use-retryable-exception branch from 8e69051 to c64f5ae Compare August 17, 2019 08:37
throw new TransportException($exception->getMessage(), 0, $exception);
}

return [];
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member

@nicolas-grekas nicolas-grekas left a 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

@Tobion
Copy link
Contributor

Tobion commented Sep 27, 2019

Thank you @surikman.

@Tobion Tobion force-pushed the messenger-doctrine-use-retryable-exception branch from c64f5ae to 9add32a Compare September 27, 2019 11:21
Tobion added a commit that referenced this pull request Sep 27, 2019
… 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
@Tobion Tobion merged commit 9add32a into symfony:4.3 Sep 27, 2019
@surikman surikman deleted the messenger-doctrine-use-retryable-exception branch September 30, 2019 06:36
@fabpot fabpot mentioned this pull request Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants