Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

abort connection at sqltransaction #299

Merged
merged 3 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 doom this connection and make sure it does not go back to the pool.
yukiwongky marked this conversation as resolved.
Show resolved Hide resolved
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 doom 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