@@ -391,21 +391,23 @@ public void SinglePhaseCommit(SysTx.SinglePhaseEnlistment enlistment)
391
391
#else
392
392
{
393
393
#endif //DEBUG
394
- lock ( connection )
394
+ // If the connection is doomed, we can be certain that the
395
+ // transaction will eventually be rolled back, and we shouldn't
396
+ // attempt to commit it.
397
+ if ( connection . IsConnectionDoomed )
395
398
{
396
- // If the connection is doomed, we can be certain that the
397
- // transaction will eventually be rolled back or has already been aborted externally, and we shouldn't
398
- // attempt to commit it.
399
- if ( connection . IsConnectionDoomed )
399
+ lock ( connection )
400
400
{
401
401
_active = false ; // set to inactive first, doesn't matter how the rest completes, this transaction is done.
402
402
_connection = null ;
403
-
404
- enlistment . Aborted ( SQL . ConnectionDoomed ( ) ) ;
405
403
}
406
- else
404
+ enlistment . Aborted ( SQL . ConnectionDoomed ( ) ) ;
405
+ }
406
+ else
407
+ {
408
+ Exception commitException ;
409
+ lock ( connection )
407
410
{
408
- Exception commitException ;
409
411
try
410
412
{
411
413
// Now that we've acquired the lock, make sure we still have valid state for this operation.
@@ -434,40 +436,40 @@ public void SinglePhaseCommit(SysTx.SinglePhaseEnlistment enlistment)
434
436
ADP . TraceExceptionWithoutRethrow ( e ) ;
435
437
connection . DoomThisConnection ( ) ;
436
438
}
437
- if ( commitException != null )
439
+ }
440
+ if ( commitException != null )
441
+ {
442
+ // connection.ExecuteTransaction failed with exception
443
+ if ( _internalTransaction . IsCommitted )
438
444
{
439
- // connection.ExecuteTransaction failed with exception
440
- if ( _internalTransaction . IsCommitted )
441
- {
442
- // Even though we got an exception, the transaction
443
- // was committed by the server.
444
- enlistment . Committed ( ) ;
445
- }
446
- else if ( _internalTransaction . IsAborted )
447
- {
448
- // The transaction was aborted, report that to
449
- // SysTx.
450
- enlistment . Aborted ( commitException ) ;
451
- }
452
- else
453
- {
454
- // The transaction is still active, we cannot
455
- // know the state of the transaction.
456
- enlistment . InDoubt ( commitException ) ;
457
- }
458
-
459
- // We eat the exception. This is called on the SysTx
460
- // thread, not the applications thread. If we don't
461
- // eat the exception an UnhandledException will occur,
462
- // causing the process to FailFast.
445
+ // Even though we got an exception, the transaction
446
+ // was committed by the server.
447
+ enlistment . Committed ( ) ;
463
448
}
464
-
465
- connection . CleanupConnectionOnTransactionCompletion ( _atomicTransaction ) ;
466
- if ( commitException == null )
449
+ else if ( _internalTransaction . IsAborted )
467
450
{
468
- // connection.ExecuteTransaction succeeded
469
- enlistment . Committed ( ) ;
451
+ // The transaction was aborted, report that to
452
+ // SysTx.
453
+ enlistment . Aborted ( commitException ) ;
470
454
}
455
+ else
456
+ {
457
+ // The transaction is still active, we cannot
458
+ // know the state of the transaction.
459
+ enlistment . InDoubt ( commitException ) ;
460
+ }
461
+
462
+ // We eat the exception. This is called on the SysTx
463
+ // thread, not the applications thread. If we don't
464
+ // eat the exception an UnhandledException will occur,
465
+ // causing the process to FailFast.
466
+ }
467
+
468
+ connection . CleanupConnectionOnTransactionCompletion ( _atomicTransaction ) ;
469
+ if ( commitException == null )
470
+ {
471
+ // connection.ExecuteTransaction succeeded
472
+ enlistment . Committed ( ) ;
471
473
}
472
474
}
473
475
}
0 commit comments