views:

112

answers:

1

When executing an NServiceBus handler that uses NHibernate for its data access operations, I am seeing an error that I am not sure if I need to be concerned with.

The handler has code that does something like this:

using (var tx = Session.BeginTransaction()) 
{
    var accountGroup = _groupRepository.FindByID(message.GroupID);
    accountGroup.CreateAccount(message.AccountNumber);

    tx.Commit();
}

When I profile this process, I see the following lines:

  • enlisted session in distributed transaction with isolation level: Serializable
  • begin transaction with isolation level: Unspecified
  • SELECT ... FROM AccountGroups this_ WHERE this_.ID = 123
  • INSERT INTO Accounts ...
  • commit transaction
  • commit transaction

The first commit message is generated by my code when I call tx.Commit(). The second commit message, I believe occurs when we leave the Handle method of the handler and is called by NServiceBus. This second call to commit generates an alert in NHProf that states "Using a single session in multiple threads is likely a bug".

I don't think this is an issue, because there really is nothing to commit at that time, but am I doing some inappropriate here? I do want to run my code within a transaction, but when I do, I get this alert.

Any ideas?

+1  A: 

This isn't an issue, what is happening is that NH Prof detects that the DTC commit is happening in another thread. It should actually handle DTC commits properly, so I am not sure what is going on. At a guess, using both DTC commit and standard commit it confusing it. I'll fix it.

Ayende Rahien
Thanks Ayende. I assumed this was ok, but thought it strange to get the alert nonetheless.
SteveBering