From 1cbdfd69895ddbfe301b6e02ba1077585be4991a Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Tue, 5 Nov 2019 17:31:22 -0800 Subject: [PATCH 1/3] abort connection at sqltransaction --- .../Data/SqlClient/SqlInternalTransaction.cs | 5 ----- .../src/Microsoft/Data/SqlClient/SqlTransaction.cs | 14 ++++++++++++++ .../src/Microsoft/Data/SqlClient/SqlTransaction.cs | 13 +++++++++++++ .../Data/SqlClient/sqlinternaltransaction.cs | 5 ----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs index 714c13d54c..4142a32119 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs @@ -298,11 +298,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(); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs index eb32a81df7..ebaf3b425c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs @@ -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; @@ -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. + 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; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs index 235ac7651d..54e58f96b5 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs @@ -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; @@ -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; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs index 28b9cb82b8..104ab79d63 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs @@ -344,11 +344,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)) { From 3c3f50065f65c44156ae97d365a6e0f5bcb16827 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Wed, 6 Nov 2019 09:59:37 -0800 Subject: [PATCH 2/3] committimeout3 --- .../Microsoft/Data/SqlClient/SqlInternalTransaction.cs | 9 --------- .../Microsoft/Data/SqlClient/sqlinternaltransaction.cs | 9 --------- 2 files changed, 18 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs index 4142a32119..5ca53cfa3a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalTransaction.cs @@ -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 diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs index 104ab79d63..540b4294e0 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/sqlinternaltransaction.cs @@ -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 From bd5369f0cd14536d21d7ca05b23e9ea7167823d6 Mon Sep 17 00:00:00 2001 From: v-kaywon Date: Fri, 8 Nov 2019 16:42:57 -0800 Subject: [PATCH 3/3] modify comment --- .../netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs | 2 +- .../netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs index ebaf3b425c..14c9f3081f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs @@ -145,7 +145,7 @@ override public void Commit() { // 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. + // 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) { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs index 54e58f96b5..53e195ad77 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlTransaction.cs @@ -193,7 +193,7 @@ override public void Commit() { // 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. + // 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) {