NServiceBus - message not always delivers and causing exception Cannot enlist the transaction

3.4k Views Asked by At

We are using NServiceBus on production, and in our log files we see the following error:

ERROR Our.Namespace.SomeMessageHandler [(null)] <(null)> - MethodName  --> end with exception: NServiceBus.Unicast.Queuing.FailedToSendMessageException: Failed to send message to address: our.namespace.worker@somemachinename ---> System.Messaging.MessageQueueException: Cannot enlist the transaction.
    at System.Messaging.MessageQueue.SendInternal(Object obj, MessageQueueTransaction internalTransaction, MessageQueueTransactionType transactionType)
    at NServiceBus.Unicast.Queuing.Msmq.MsmqMessageSender.NServiceBus.Unicast.Queuing.ISendMessages.Send(TransportMessage message, Address address)
    --- End of inner exception stack trace ---
    at NServiceBus.Unicast.Queuing.Msmq.MsmqMessageSender.ThrowFailedToSendException(Address address, Exception ex)
    at NServiceBus.Unicast.Queuing.Msmq.MsmqMessageSender.NServiceBus.Unicast.Queuing.ISendMessages.Send(TransportMessage message, Address address)
    at NServiceBus.Unicast.UnicastBus.SendMessage(List`1 addresses, String correlationId, MessageIntentEnum messageIntent, Object[] messages)
    at NServiceBus.Unicast.UnicastBus.SendMessage(Address address, String correlationId, MessageIntentEnum messageIntent, Object[] messages)
    at NServiceBus.Unicast.UnicastBus.NServiceBus.IBus.Send(Address address, Object[] messages)
    at Our.Namespace.SomeMessageHandler.MethodName(EventLogVO eventLog, IApplicationContext applContext, CreateEventLogHistory message)

The queue on the target machine exists (double checked). The strange thing here is that it doesn't happen all the time and for each message sent to that queue, but happens occasionally (which means that there are messages that arrive to that queue).

Searched and didn't find a similar case.

What am I missing here?

2

There are 2 best solutions below

1
Adam Fyles On BEST ANSWER

We recently had this error and tracked it down to be one of the following:

  • Database performance. We had a long running query that we tuned up, but the problem persisted.
  • Large transaction scope. You may be doing something that would cause too many resource managers to be involved.
  • MSMQ Resources. Ultimately our disk was not fast enough to perform the IO required for what we were doing with MSMQ.

I would try to track down the true source (hopefully you get some ideas from above). But if all else fails, first turn on the System.Transactions logging to see if it is truly a timeout. If it is, then use this section in the app.config

0
Hugo Forte On

I had this happen to me in a handler that took over a minute to complete, I ended up increasing the timeout by adding this to the app.config

<system.transactions>
  <defaultSettings timeout="00:05:00"/>
</system.transactions>

As per this: https://erictummers.wordpress.com/2014/05/28/cannot-enlist-the-transaction/

Additionally, I changed machine config as per this post: http://blogs.msdn.com/b/ajit/archive/2008/06/18/override-the-system-transactions-default-timeout-of-10-minutes-in-the-code.aspx

I also wrote a quick app that edits the machine.configs: https://github.com/hfortegcmlp/MachineConfigEditor