Fix issue with message payload being disposed while resending #282
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #281
Motivation
When the producer resending the message, it would throw the following error:
The root cause is that the payload would be disposed regardless of whether the send is successful. And if there is some issue when the message is inflight, like a network issue after sending the message. The producer will resend the message. But now the message payload has already been disposed, so the clientCnx will fail to process the payload MemoryStream and throw an exception.
Modification
Verification
I added a unit test for asserting the payload won't be deposed after
serializeDeserializePayloadCommand
. But it's hard to reproduce the reconnection in the unit test.I have also verified that this PR could fix the issue: #281. I tested it by forcing the reconnecting and the producer could resend the messages successfully. Otherwise without this fix, it could sometimes get stuck resending messages due to the serialization error.