NServiceBus is a powerful and easy-to-use platform and it’s asynchronous messaging enables you to handle long-running processing tasks without blocking your main application. Ok, most of the time you should try to avoid long running tasks: there’s a fair chance it’s running so long because of something evil, but there can be situations where your tasks just needs some time to complete – for example when you’re calling an external web service or when you need to process a lot of data.
Still no problem…… except when your task takes longer than 60 seconds to complete, then you’ll end up with Cannot enlist the transaction
exceptions in your log. What happens in this case is as follows:
- NServiceBus starts a new distributed transaction using the DTC
- The messages is taken from the queue and the message handler starts doing its work
- On completion, NServiceBus tries to commit the started transaction, but the transaction is gone: it was already discarded by the DTC after 60 seconds.
This can be deceiving as the system default timeout of the DTC is 10 minutes. Still, the transaction times out after 60 seconds. Don’t bother trying to change the default timeout (I already did)… it makes no difference.
I suspect it’s the System.Transactions of .NET that overrules the system timeout as adding the setting below to the configuration section of the config solves the issue:
<system.transactions>
<defaultSettings timeout="00:10:00"/>
</system.transactions>
You can also check out Eric Tummers’ blog for more info.