Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Requeue of a possibly mutated message on failure #36735

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

Closed
tjveldhuizen opened this issue May 7, 2020 · 11 comments
Closed

[Messenger] Requeue of a possibly mutated message on failure #36735

tjveldhuizen opened this issue May 7, 2020 · 11 comments

Comments

@tjveldhuizen
Copy link
Contributor

Symfony version(s) affected: 4.4, 5.*

Description
When an exception occurs during handling a message, it is requeued following the (default or specific) configuration. In my opinion the message (except from extra stamps on the envelope) should be the same as the original message.
However, when the message object is mutated during handling, the modified message is serialized again before requeueing happens.

How to reproduce
https://github.com/tjveldhuizen/symfony-mutable-message-reproducer

$ rm var/data.db
$ bin/console app:test
$ bin/console messenger:consume async -l8
$ bin/console messenger:failed:show 9 -vv
$ bin/console messenger:failed:show 10 -vv

In message 9, the ArrayCollection contains no elements anymore.
In message 10, the content has four (original + 3 retries) exclamation marks added.

Possible Solution
I think modifying the message is bad practice, however (as shown with the ArrayCollection) might happen unnoticed. It took a lot of time to figure out what was happening, so at least some prevention would be appreciated. The easiest being to state in the documentation that a message should be designed being immutable.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@Nommyde
Copy link
Contributor

Nommyde commented Dec 21, 2021

There is a real case related to this issue. When an email is sent through the messenger using alternative mail transport and if this mail transport fails then modified email is pushed to the queue for the next try (without X-Transport header). The second try takes default mail transport whether you want it or not.

In this case I believe the method \Symfony\Component\Mailer\Transport\Transports::send should clone a message before modifying and sending it.

@Nommyde
Copy link
Contributor

Nommyde commented Dec 21, 2021

@carsonbot this is still relevant

@Nommyde
Copy link
Contributor

Nommyde commented Dec 21, 2021

I've created a separate issue for the email case: #44741

@nicolas-grekas
Copy link
Member

Would you mind sending a PR to the doc @Nommyde or @tjveldhuizen?
Or have a look at the code to see what we can do about that?

@carsonbot carsonbot removed the Stalled label Dec 21, 2021
@tjveldhuizen
Copy link
Contributor Author

Do we know situations in which mutability of the message should be qualified as a feature? Or is it always a bad idea? I think that's also relevant for the kind of addition to the docs.
If no valid use cases are available and we change the code, should we add a feature flag or something like that, to prevent a BC break? Or is the fact that it's mutable a bug, which has to be fixed? A possible fix might be to clone the message payload directly after deserialization and using the original deserialized payload when it's dispatched to the queue again.

@nicolas-grekas
Copy link
Member

I don't think there is any case where mutability of the message is legit.

@fabpot
Copy link
Member

fabpot commented Jul 27, 2022

I don't see what we can fix here.
The transport issue has already been fixed.

@javiereguiluz
Copy link
Member

Let's close this old issue because it looks like the latest consensus is that we can't/shouldn't do more changes about this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants