views:

199

answers:

4

I have a multithreaded C# application where each thread has it's own set of db connections. Each thread uses TransactionScope / DTC. Sometimes, I get a "The transaction has aborted" exception. It's not from a timeout since it occurs in less than 2 seconds from starting the transaction.

Here's the stacktrace:

at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState) at System.Transactions.CommittableTransaction.Commit() at System.Transactions.TransactionScope.InternalDispose() at System.Transactions.TransactionScope.Dispose() at MyNamespace.CallingMethod()

It happenes very infrequently, say once in 100,000 transactions.

Environment: Windows Server 2003 .Net 2.0 Connects to SqlServer 2005

Any ideas on why this is occuring? Thanks!

A: 

If you had connection pooling on I could see how you might get a Heisen Bug.

Conrad Frix
can you please explain a bit more?
StingyJack
I do have connection pooling on... searching now on google for what a Heisen Bug is.
Dan
:) yes, it is a Heisenbug! As far as I know, there is no race condition, I used to have deadlocks, but all that has been sorted out for years. Talk about an education in threading/race conditions/deadlocking/pagelocks/transaction suppression/sql bugs/etc.I do have another similar bug that I can reproduce easily where a thread gets left behind during the Complete() call on TransactionScope. I'll post that in another question, as I think it may be a bug in the TransactionScope code where a thread is going to sleep as all the sleeper are notified to wake up and gets missed.
Dan
I can see how a debugger can cause a heisenbug, but not connection pooling (not obervational). Thats the explanation I am asking for.
StingyJack
No, I haven't caught this in a debugger yet, unfortunately.
Dan
+1  A: 

Is this call stack from your inner-most InnerException? I you get this exceptions, there is usually (not always, though) an InnerException with more info.

My bet would be on a database deadlock.

Andreas Paulsson
Yes, this was the inner most exception. I have access to deadlock traces, and none were found during this time.
Dan
A: 

You can create a memory dump, the instruction can be found here http://blogs.msdn.com/b/joncole/archive/2007/03/29/creating-a-process-memory-dump.aspx

Then you can check with windbg to reveal what's root exception caused this issue. There are lots of useful information about how to use windbg check the managed exception.

in the mean time , you can use sql profiler to monitor if any sql error happened around the time when the exception was thrown.

Russel Yang
I like this idea. I'm going to again try and recreate this in dev and get an answer to this problem.
Dan
If you have memory dump, I can check it for you. you can put it on skydrive public folder.
Russel Yang
A: 

As Andreas said, look at the InnerExceptions. Also hook up SQL Profiler and look for any deadlocks/terminates.

Robert Wagner