Closed DorianGreen closed 2 months ago
@DorianGreen thank you for your contribution. We will look into the problem and get back to you with more information.
Thanks @tmasternak for the quick response.
Would it be possible to wrap the exception in the control message path with a message that would include the control message value?
For message based replies it might be hard or impossible to include the body, but with control messages we have the actual value.
At least in out legacy case we would like to access the value and could extract it from the exception if possible
Hi @DorianGreen, regarding
(...) we would like to access the value and could extract it from the exception if possible
we discussed introducing this change and realized that this would likely have harmful consequences for the overall NServiceBus API usability.
The fact, that the expected message type and the received type do not match, likely indicates a bigger problem with the code, and in most cases we want our users to solve it at that (code change and redeployment) level.
Secondly, as you already mentioned this would be possible only for control-message-based responses, and would likely boil down to exposing the response as a string
. This in turn would bring inconsistency to the callbacks API.
Finally, for control messages and normal messages, you can already write a custom pipeline behavior that could catch the casting error and have access to the incoming message - both headers and body.
Symptoms
When a user awaits a callback task e.g.:
and the actual response received is different than the expected (i.e.
MyResponse
), the task will never be completed.Who's affected
All users of:
3.0.0
4.0.0
5.0.0
Root cause
The problem is caused by the fact that the response-handling behaviors do not complete the completion sources for callback tasks when an exception is thrown while setting the result. Both when received response is a C# class:
https://github.com/Particular/NServiceBus.Callbacks/blob/6ca6db4080be89789a7d372c9a0af55e0d3c2eb8/src/NServiceBus.Callbacks/Reply/RequestResponseInvocationForMessagesBehavior.cs#L30
and when it is
int
orEnum
https://github.com/Particular/NServiceBus.Callbacks/blob/6ca6db4080be89789a7d372c9a0af55e0d3c2eb8/src/NServiceBus.Callbacks/Reply/RequestResponseInvocationForControlMessagesBehavior.cs#L37
Backported to
588
589
590
Fixed in