symfony: [Messenger] ErrorDetailsStamp +RedeliveryStamp can lead to an oversize message for SQS
Symfony version(s) affected
5.4
Description
SQS has a limit of 262,144 bytes (256 KB) message size.
When there is an error during message handling, the ErrorDetailsStamp adds a stacktrace that can lead to a message bigger than this limit.
How to reproduce
- Dispatch messages with SQS with a redelivery policy that makes it retry a few times
- Throw an exception with a super big stack trace
- See it fails
Possible Solution
Not sure, maybe an option to remove stack trace from ErrorDetailsStamp
Additional Context
No response
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 30
- Comments: 18 (11 by maintainers)
Just in case anyone needs a workaround: https://github.com/mtanasiewicz/symfony-messenger-sqs-workaround
With rabbitmq and the amqp PHP library, the header limit is even just 128 KB (overall, not per header). I adjusted our application to remove the error details stamp alltogether (which would not be a good general solution of course). How about a configuration for the allowed header size (that maybe could be default to the correct value if known?) and in addition to reduce verbosity of the stack trace also shorten the trace to strictly prevent errors even on very deep traces with long namespaces?
its tricky that the limit is overall. maybe serialize everything, then check the length and if it is too long shorten the error details by the difference + 100 bytes of safety margin?
btw: i am surprised that the amqp library allows to send messages that break the system, they could check the header limit on sending as well and not only on receiving…
I have same problem while using SQS. I cheched stack trace and main problem for oversized messages is, that arguments of functions are serialized too.
aws/aws-sdk-phppackage contains more functions, that receives whole serialized message as string. If those functions are called 4 times in one run and after retry 4 more times, size of the envelope grows exponentially.I can think of one solution: You can override
Symfony\Component\Messenger\EventListener\AddErrorDetailsStampListenerand create customSymfony\Component\Messenger\Stamp\ErrorDetailsStampwith exception without function argumets. This can downsize message drastically.It is only a theory, I must try it. With this solution you lose function arguments in stack trace, but better than oversized message.