Skip to content

Commit

Permalink
Fix | Abort connection at SqlTransaction (#299)
Browse files Browse the repository at this point in the history
  • Loading branch information
yukiwongky authored and cheenamalhotra committed Nov 14, 2019
1 parent 929a56b commit ffd47e9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,6 @@ internal void Activate()
_transactionState = TransactionState.Active;
}

private void DoomConnectionNoReuse(SqlInternalConnection innerConnection)
{
if (null != innerConnection)
{
innerConnection.DoNotPoolThisConnection();
innerConnection.DoomThisConnection();
}
}

private void CheckTransactionLevelAndZombie()
{
try
Expand Down Expand Up @@ -298,11 +289,6 @@ internal void Commit()
}
catch (Exception e)
{
// GitHub Issue #130 - When an exception has occurred on transaction completion request,
// this connection may not be in reusable state.
// We will doom this connection and make sure it does not go back to the pool.
DoomConnectionNoReuse(_innerConnection);

if (ADP.IsCatchableExceptionType(e))
{
CheckTransactionLevelAndZombie();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
Expand Down Expand Up @@ -140,6 +141,19 @@ override public void Commit()

_internalTransaction.Commit();
}
catch (SqlException ex)
{
// GitHub Issue #130 - When a timeout exception has occurred on transaction completion request,
// this connection may not be in reusable state.
// We will abort this connection and make sure it does not go back to the pool.
var innerException = ex.InnerException as Win32Exception;
if (innerException != null && innerException.NativeErrorCode == TdsEnums.SNI_WAIT_TIMEOUT)
{
_connection.Abort(ex);
}
e = ex;
throw;
}
catch (Exception ex)
{
e = ex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
Expand Down Expand Up @@ -188,6 +189,18 @@ override public void Commit()
SqlInternalConnection.BestEffortCleanup(bestEffortCleanupTarget);
throw;
}
catch (SqlException e)
{
// GitHub Issue #130 - When a timeout exception has occurred on transaction completion request,
// this connection may not be in reusable state.
// We will abort this connection and make sure it does not go back to the pool.
var innerException = e.InnerException as Win32Exception;
if (innerException != null && innerException.NativeErrorCode == TdsEnums.SNI_WAIT_TIMEOUT)
{
_connection.Abort(e);
}
throw;
}
finally
{
_isFromAPI = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,6 @@ internal void Activate()
_transactionState = TransactionState.Active;
}

private void DoomConnectionNoReuse(SqlInternalConnection innerConnection)
{
if (null != innerConnection)
{
innerConnection.DoNotPoolThisConnection();
innerConnection.DoomThisConnection();
}
}

private void CheckTransactionLevelAndZombie()
{
try
Expand Down Expand Up @@ -344,11 +335,6 @@ internal void Commit()
}
catch (Exception e)
{
// GitHub Issue #130 - When an exception has occurred on transaction completion request,
// this connection may not be in reusable state.
// We will doom this connection and make sure it does not go back to the pool.
DoomConnectionNoReuse(_innerConnection);

// UNDONE - should not be catching all exceptions!!!
if (ADP.IsCatchableExceptionType(e))
{
Expand Down

0 comments on commit ffd47e9

Please sign in to comment.