Skip to content

[Messenger] Proper message decoding error handling #50043

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

Conversation

alex-dev
Copy link
Contributor

@alex-dev alex-dev commented Apr 17, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
BC breaks? yes
Tickets Fix #44117
License MIT
Doc PR N/A
  • Update CHANGELOG.md
  • Update whatever is needed for BC breaks
  • Ensure serialization works across a full failing message (failed decoding into encoding)

Problem

Handling deserialization in transports prevents actual error handling from running... And depending on transports, can even drop messages. While envelope and stamps deserialization failures may be actual error warranting undefined behavior, message denormalization failures is merely an application concern. Symfony should never drop messages that are broken by the application.

Solution

Reusing some part of #39622:

  • Ensure both PhpSerializer and Serializer do not throw error in message deserialization
    • Stamps and envelope are still allowed to throw.
    • Remove toggling incomplete classes from PhpSerializer
  • Handle MessageDecodingFailedStamp in Worker
    • Trigger standard message rejection (event and retry into full rejection)
  • Ensure compatibility with AbstractFailedMessagesCommand

BC breaks

  • Messenger\Transport\Serialization\Serializer::__construct() first arguments goes from ?SerializerInterface $serializer = null to DecoderInterface&DenormalizerInterface&SerializerInterface $serializer
    • To support distinguishing between encoding errors and normalization errors, we must call each separately. This requires an intersection of interfaces
    • Framework always pass a constructed serializer, so no issue
    • No other instantiations are done... So only BC breaks will be in standalone uses passing null as first argument
    • Messenger\Transport\Serialization\Serializer::create() still return a default constructed instance

@carsonbot carsonbot added this to the 6.3 milestone Apr 17, 2023
@alex-dev alex-dev force-pushed the serializer-error-proper-error-handling branch from 94409d1 to 5a01ab9 Compare April 17, 2023 17:24
@alex-dev alex-dev force-pushed the serializer-error-proper-error-handling branch 4 times, most recently from 72a5cb3 to 08b0850 Compare April 24, 2023 13:37
@alex-dev
Copy link
Contributor Author

@lyrixx Here is a fix for #44117

@alex-dev alex-dev force-pushed the serializer-error-proper-error-handling branch 2 times, most recently from 6f0f923 to 796da17 Compare April 25, 2023 13:32
@alex-dev alex-dev force-pushed the serializer-error-proper-error-handling branch from 60068ef to d3f1e14 Compare May 15, 2023 14:57
@alex-dev alex-dev force-pushed the serializer-error-proper-error-handling branch from d3f1e14 to 67fb47c Compare May 15, 2023 16:26
@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@alex-dev alex-dev closed this Nov 3, 2023
@ismail1432
Copy link
Contributor

ismail1432 commented Nov 9, 2023

Hello @alex-dev,
I think this fix is important, why the PR was closed?

@alex-dev
Copy link
Contributor Author

alex-dev commented Nov 9, 2023

I could not justify spending more time on this to update it. Seeing Symfony had little interest in this fix, my company chose to implement a solution inside the transport layer. It is hacked, but the right behavior is guaranteed.
If thee is clear interest in this, I may reopen in January.

@B-Galati
Copy link
Contributor

@alex-dev any chance you could share your solution?

@alex-dev
Copy link
Contributor Author

We just reimplemented the transport and made rejection a no-op. There are a few annoying caveats.

  • Retries and failures must be handled by the queue itself (SQS does).
  • You lose a lot of debugging utilities Symfony gives you (you must unconfigure failure handling from Symfony)

Other alternative would be to reimplement the worker and associated commands (what this PR more or less does).

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.

[Messenger] MessageDecodingFailedException should not delete message from queue
6 participants