Skip to content
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] Add support for RecoverableException #36557

Merged
merged 1 commit into from May 4, 2020

Conversation

jderusse
Copy link
Member

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets N/A
License MIT
Doc PR N/A

The messenger supports the UnrecoverableException preventing the messenger retry mechanism
when the Handler will never be able to process the Message.

This PR adds the opposite behavior to always retry the message.

UseCase:

  • High concurency Consumers use non-blocking lock
  • 503/429 errors from 3rd party API

@jderusse jderusse requested a review from sroze as a code owner April 23, 2020 23:25
@jderusse jderusse changed the title Add support for RecoverableException [Messenger] Add support for RecoverableException Apr 23, 2020
@nicolas-grekas nicolas-grekas added this to the next milestone Apr 24, 2020
@@ -87,6 +88,10 @@ public static function getSubscribedEvents()

private function shouldRetry(\Throwable $e, Envelope $envelope, RetryStrategyInterface $retryStrategy): bool
{
if ($e instanceof RecoverableExceptionInterface) {
return true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the HandlerFailedException case where you need to check for the nested exceptions?

Also, a new test case for the listener would be ideal :)

@nicolas-grekas
Copy link
Member

(small rebase needed)

@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
@jderusse
Copy link
Member Author

jderusse commented May 4, 2020

rebased

@fabpot
Copy link
Member

fabpot commented May 4, 2020

Thank you @jderusse.

@fabpot fabpot merged commit 0d4bba8 into symfony:master May 4, 2020
@fabpot fabpot mentioned this pull request May 5, 2020
@jderusse jderusse deleted the messenger-recoverable branch October 15, 2020 10:01
fabpot added a commit that referenced this pull request May 12, 2023
…rategy for re-delivery (FlyingDR)

This PR was merged into the 5.4 branch.

Discussion
----------

[Messenger] Respect `isRetryable` decision of the retry strategy for re-delivery

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

[Documentation](https://symfony.com/doc/5.4/messenger.html#retries-failures) for retry strategy for the Messenger component declares that message will not be retried to be re-delivered more than the value of `max_retries` configuration for the retry strategy.

However, after merging #36557 [actual implementation](https://github.com/symfony/symfony/blob/39cd93a9f7ea072b26853e87ceb1142d6dd019b0/src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php#L126-L128) gives priority to the existence of the `RecoverableExceptionInterface`, effectively opening a way for a message to be re-delivered indefinitely.

Additionally, in the case of using `multiplier` with a value of more than 1 this unlimited re-delivery causes unlimited growth of the `delay` value for the `DelayStamp`. Its type is defined as `int`, so on 32-bit platforms after some time `delay` value may exceed `PHP_INT_MAX` which will lead to the `TypeError`.

The proposed change enforces respect for the `max_retries` setting value for the decision of re-delivery.

Commits
-------

8fc3dcc [Messenger] Respect `isRetryable` decision of the retry strategy when deciding if failed message should be re-delivered
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.

None yet

6 participants