10000 [Messenger] PhpSerializer: TypeError should throw `MessageDecodingFailedException` by B-Galati · Pull Request #53183 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] PhpSerializer: TypeError should throw MessageDecodingFailedException #53183

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.

8000

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
merged 1 commit into from
Jan 30, 2024

Conversation

B-Galati
Copy link
Contributor
@B-Galati B-Galati commented Dec 22, 2023
Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #...
License MIT

At the moment, some unserialization issues don't throw a MessageDecodingFailedException which prevent transport to trigger their decoding failure logic.

There are many possibilities to fix the issue. I've implemented a very conservative one. I believe we could simplify the code by a lot if we rely on the global error handler in user land.

@carsonbot carsonbot added this to the 6.4 milestone Dec 22, 2023
@B-Galati B-Galati changed the title [Messenger] Handle TypeError and more with PhpSerializer [Messenger] PhpSerializer: TypeError should throw MessageDecodingFailedException Dec 22, 2023
@B-Galati B-Galati force-pushed the messenger-php-serializer branch from 3f55e5e to 7c777ed Compare December 22, 2023 09:47
@B-Galati
Copy link
Contributor Author

Should it target version 5.4 actually?

@OskarStark OskarStark changed the title [Messenger] PhpSerializer: TypeError should throw MessageDecodingFailedException [Messenger] PhpSerializer: TypeError should throw MessageDecodingFailedException Dec 22, 2023
@OskarStark
Copy link
Contributor

Should it target version 5.4 actually?

No 8000 t sure, for me this is a feature and should target 7.1

@nicolas-grekas @fabpot please decide

@nicolas-grekas
Copy link
Member

Changing the type of thrown exceptions is not a bug fix so that's for 7.1 to me.

@B-Galati
Copy link
Contributor Author
B-Galati commented Dec 28, 2023

@nicolas-grekas I think it should have been handled since the beginning because it's an unserialization issue that currently ends with generic kind of exception instead of MessageDecodingFailedException.

I think I do not understand what's the BC break or added functionality here. For me that's a better error handling logic.

Anyway I will let you know when it's ready for 7.1 👍

If you can explain me further why it's not bugfix I would be glad 😊

@B-Galati
Copy link
Contributor Author
B-Galati commented Jan 3, 2024

Any chance to get some new feedbacks based on my last comment before rebasing?

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.

works for me on 5.4

@B-Galati B-Galati force-pushed the messenger-php-serializer branch from df6786e to ed65b77 Compare January 30, 2024 07:56
@B-Galati B-Galati changed the base branch from 6.4 to 5.4 January 30, 2024 07:57
@B-Galati B-Galati force-pushed the messenger-php-serializer branch 3 times, most recently from 6acc9d8 to d896fbf Compare January 30, 2024 10:49

namespace Symfony\Component\Messenger\Tests\Fixtures;

class DummyMessageTyped implements DummyMessageInterface
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to add a new object with typed property to assess the behavior of the test.

Can be removed with Symfony 6.0+

@@ -99,6 +100,22 @@ public function testNonUtf8IsBase64Encoded()
$this->assertTrue((bool) preg_match('//u', $encoded['body']), 'Encodes non-UTF8 payloads');
$this->assertEquals($envelope, $serializer->decode($encoded));
}

/**
* @requires PHP >= 7.4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Requirement can be removed with Symfony 6.0+

@B-Galati B-Galati force-pushed the messenger-php-serializer branch from d896fbf to 18e0030 Compare January 30, 2024 10:51
@B-Galati
Copy link
Contributor Author

@nicolas-grekas @OskarStark thanks for the review, It's ready for 5.4 👍

Let me know for any other updates that should be performed.

@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 5.4 Jan 30, 2024
…edException

Actually, the fix should handle more cases than only TypeError.
@nicolas-grekas nicolas-grekas force-pushed the messenger-php-serializer branch from 18e0030 to ebe5c3a Compare January 30, 2024 11:13
@nicolas-grekas
Copy link
Member

Thank you @B-Galati.

@nicolas-grekas nicolas-grekas merged commit 27346bc into symfony:5.4 Jan 30, 2024
@B-Galati
Copy link
Contributor Author

Thank @nicolas-grekas!

BTW, I think we could prevent message losses upon MessageDecodingFailedException by requeuing the message in the configured failed_queue. We could even configure a dedicated queue.

That could be implemented with either a new MessageDecodingFailedEvent or by transports directly.

What do you think? It would fix #44117

I implemented such a behavior for my company thanks to a custom transport but I would prefer to have the behavior built in Symfony.

if (__FILE__ === $file) {
throw $signalingException;
throw new \ErrorException($msg, 0, $type, $file, $line);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks that's going to be more debug-able like this 👍

@nicolas-grekas
Copy link
Member

I don't know, please follow up on an open issue or a PR :)

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.

4 participants
0