InvalidOperationException with message "An error occurred when attempting to complete the transaction context" #1180
-
Implemented a very simple message handler, but getting an InvalidOperationException after the
(Source of this exception, introduced in the "fix some stuff" commit.) public Task Handle(MyMessage message)
{
_logger.LogInformation("Receive my message");
return Task.CompletedTask;
} The message is not completed in Azure Service Bus. I have to call We configure Rebus for Azure Service Bus like this: configurer.Transport(t =>
{
t.UseAzureServiceBus(azureServiceBusConnectionString, queue, tokenCredential);
t.UseNativeDeadlettering();
} How should I configure Rebus so that we don't need a call to |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
That sounds very weird, because that's clearly supposed to work. Could you check out this example and figure out how your code differs from it? |
Beta Was this translation helpful? Give feedback.
-
Thanks for the link! I ran that test locally and it works. You asked for the differences, and our code does contain some custom middleware. I must admit I do not have experience working with Rebus transactions. Would it still be possible that our middleware does something to trigger this check, despite not doing anything with Could you help me understand that by answering the following question: When I set a breakpoint in If I know why Thanks! |
Beta Was this translation helpful? Give feedback.
-
Simply because I suggest you try running your handler without any of your custom middlewares to begin with, and then you enable them, one by one, to see what could be the possible source of the error (here assuming, of course, that it runs without errors without the middlewares). OTOH if you can reproduce the error without any of your own customizations when I would be happy to debug it. |
Beta Was this translation helpful? Give feedback.
-
Thanks again for your help @mookid8000. The problem was that we removed Solution: don't remove the default retry step, and instead learn how to take advantage of the retry mechanism it offers. |
Beta Was this translation helpful? Give feedback.
Thanks again for your help @mookid8000.
The problem was that we removed
DefaultRetryStep
. Probably because we wanted to rely on Azure Service Bus for retries and dead-lettering (and use our logs to diagnose the root cause of dead-lettered messages, since we always log correlation ID and message ID). This was in the v6 timeframe, and back then removing the step did not cause any problems. But after updating to v8 removing the default retry step started causing problems, because that is the step that is responsible for callingSetResult()
(here).Solution: don't remove the default retry step, and instead learn how to take advantage of the retry mechanism it offers.