Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Messenger] Ensure message is handled only once per handler#30020
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
5a1bcec toe77c757CompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
e77c757 to1826b88Comparesroze commentedMar 23, 2019
We need to wait for#30557 to be merged to go forward with this one because we need to make sure the But either way, wouldn't it make more sense to retry all the listeners by default? It might cause even more inconsistency if we only call the "remaining listeners" isn't it? (only if they are related to each other I guess) |
fabpot commentedMar 23, 2019
#30557 is merged now :) |
weaverryan commentedMar 24, 2019
@keulinho can you rebase now that#30557 is merged? This is a missing piece to handling failures correctly. It could be a bit more complex, but I'm wondering if we should add an integration test involving
Hmm, I don't think I agree with this. It seems like more risk to knowingly execute a handler two times. |
1826b88 tof18bd98Compare92065aa todca8b9eComparesrc/Symfony/Component/Messenger/Exception/ChainedHandlerFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Tests/Fixtures/DummyMessageHandler.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Tests/Fixtures/DummyMessageHandler.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Tests/Fixtures/DummyMessageHandler.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
117ec51 to7c6fb32Compareweaverryan commentedMar 31, 2019
@keulinho could you please rebase again? And mark the previous comments as "Resolved" if you've handled them. A lot of things are being merged to messenger currently - so sorry for the repeated rebasing! |
713158c to1cdf048Comparesrc/Symfony/Component/Messenger/Exception/ChainedHandlerFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Exception/ChainedHandlerFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
1cdf048 toa0c04e4Comparesroze commentedApr 6, 2019
I've changed the exception name to |
src/Symfony/Component/Messenger/Exception/HandlerFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Messenger/Exception/HandlerFailedException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| $handledStamp = HandledStamp::fromCallable($handler,$handler($message),\is_string($alias) ?$alias :null); | ||
| $envelope =$envelope->with($handledStamp); | ||
| $this->logger->info('Message "{class}" handled by "{handler}"',$context + ['handler' =>$handledStamp->getCallableName()]); | ||
| $alias =\is_string($alias) ?$alias :null; |
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.
What if$alias is null and there are 2 handlers? Wouldn't that cause the second one to "appear" like it was handled? I think if the$alias is null, we have to assume that the message hasnot already been handled always.
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.
They would not appear as handled because we track the handler name. Alias is just an optional thing we actually don't use in core. (I think we could even remove it, it's been introduced -#29166 - on the assumption that it might be useful later, while it complexifies reading this code).
| if (\count($exceptions)) { | ||
| thrownewHandlerFailedException($envelope, ...$exceptions); | ||
| } |
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.
Just thinking out loud: one practical implication is that, if someone listens on the newWorkerMessageFailedEvent event, they will always (well, not technically "always", but pretty much always) receivethis exception instead of the actual exception. Then they'll need to loop overgetNestedExceptions() if they want to look for a specific exception. I think that's ok, just stating that.
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.
Yes, exactly. I was thinking whether it would make sense or not to throw the original exception if there is only one but it would mean you need to catch your own exception plusHandlerFailedException. So better always throwing it.
src/Symfony/Component/Messenger/Tests/Fixtures/MessageHandlerFailingFirstTimes.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
4fc0e80 to2bd4d29CompareAdd check to ensure that a message is only handled once per handlerAdd try...catch to run all handlers before throwing exception
2bd4d29 to2e5e910Comparefabpot commentedApr 6, 2019
Thank you@keulinho. |
…ndler (keulinho, sroze)This PR was merged into the 4.3-dev branch.Discussion----------[Messenger] Ensure message is handled only once per handlerAdd check to ensure that a message is only handled once per handlerAdd try...catch to run all handlers before throwing exception| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? |no| Tests pass? | yes| Fixed tickets |#27215| License | MIT| Doc PR | TodoThis would make error handling and retrying of messages much more easier. As statet here#27008 (comment) there is currently no way to retry a for all failed handlers if there are mutliple handlers and just some throw an exception.Also if an Exception in an handler occurs the execution chain is disrupted and the other handlers are never invoked.With this change it is easily possible to create an userland middleware that catches the `ChainedHandlerFailedException` and does some custom retry logic. If you ensure that the `HandledStamps` on the `Envelope` are preserved the message will be handled just by the failed handlersCommits-------2e5e910 Rename exception, add change log and a few other thingse6e4cde Ensure message is handled only once per handler
Uh oh!
There was an error while loading.Please reload this page.
Add check to ensure that a message is only handled once per handler
Add try...catch to run all handlers before throwing exception
This would make error handling and retrying of messages much more easier. As statet here#27008 (comment) there is currently no way to retry a for all failed handlers if there are mutliple handlers and just some throw an exception.
Also if an Exception in an handler occurs the execution chain is disrupted and the other handlers are never invoked.
With this change it is easily possible to create an userland middleware that catches the
ChainedHandlerFailedExceptionand does some custom retry logic. If you ensure that theHandledStampson theEnvelopeare preserved the message will be handled just by the failed handlers