Skip to content

Commit 8404641

Browse files
Changes to not throw exception is Abort cannot be done.
1 parent c7026fb commit 8404641

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -265,17 +265,16 @@ public Byte[] Promote()
265265
public void Rollback(SysTx.SinglePhaseEnlistment enlistment)
266266
{
267267
Debug.Assert(null != enlistment, "null enlistment?");
268-
269-
SqlInternalConnection connection = GetValidConnection();
270-
SqlConnection usersConnection = connection.Connection;
271-
SqlClientEventSource.Log.TraceEvent("<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection {1}, aborting transaction.", ObjectID, connection.ObjectID);
272-
RuntimeHelpers.PrepareConstrainedRegions();
268+
SqlInternalConnection connection = null;
273269

274270
try
275271
{
276272
#if DEBUG
277273
TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection();
278274

275+
connection = GetValidConnection();
276+
SqlConnection usersConnection = connection.Connection;
277+
SqlClientEventSource.Log.TraceEvent("<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection {1}, aborting transaction.", ObjectID, connection.ObjectID);
279278
RuntimeHelpers.PrepareConstrainedRegions();
280279
try
281280
{
@@ -331,27 +330,36 @@ public void Rollback(SysTx.SinglePhaseEnlistment enlistment)
331330
connection.CleanupConnectionOnTransactionCompletion(_atomicTransaction);
332331
enlistment.Aborted();
333332
}
333+
catch (System.OutOfMemoryException e)
334+
{
335+
usersConnection.Abort(e);
336+
throw;
337+
}
338+
catch (System.StackOverflowException e)
339+
{
340+
usersConnection.Abort(e);
341+
throw;
342+
}
343+
catch (System.Threading.ThreadAbortException e)
344+
{
345+
usersConnection.Abort(e);
346+
throw;
347+
}
334348
#if DEBUG
335349
finally
336350
{
337351
tdsReliabilitySection.Stop();
338352
}
339353
#endif //DEBUG
340354
}
341-
catch (System.OutOfMemoryException e)
355+
catch (ObjectDisposedException)
342356
{
343-
usersConnection.Abort(e);
344-
throw;
345-
}
346-
catch (System.StackOverflowException e)
347-
{
348-
usersConnection.Abort(e);
349-
throw;
350-
}
351-
catch (System.Threading.ThreadAbortException e)
352-
{
353-
usersConnection.Abort(e);
354-
throw;
357+
if (_atomicTransaction.TransactionInformation.Status == SysTx.TransactionStatus.Active)
358+
{
359+
throw;
360+
}
361+
// Do not throw exception if connection is already aborted/ended from another thread,
362+
// replicate as done in TransactionEnded event handler.
355363
}
356364
}
357365

0 commit comments

Comments
 (0)