Skip to content

Commit d6b8f77

Browse files
[5.1.6] | Revert the fix transient fault handling issue with OpenAsync (#1983) (#2508)
1 parent 0de9681 commit d6b8f77

File tree

4 files changed

+8
-85
lines changed

4 files changed

+8
-85
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
18201820
}
18211821
}
18221822

1823-
_applyTransientFaultHandling = (!overrides.HasFlag(SqlConnectionOverrides.OpenWithoutRetry) && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
1823+
_applyTransientFaultHandling = (!overrides.HasFlag(SqlConnectionOverrides.OpenWithoutRetry) && retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
18241824

18251825
if (connectionOptions != null &&
18261826
(connectionOptions.Authentication == SqlAuthenticationMethod.SqlPassword ||
@@ -1849,7 +1849,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
18491849
// does not require GC.KeepAlive(this) because of ReRegisterForFinalize below.
18501850

18511851
// Set future transient fault handling based on connection options
1852-
_applyTransientFaultHandling = connectionOptions != null && connectionOptions.ConnectRetryCount > 0;
1852+
_applyTransientFaultHandling = (retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
18531853

18541854
var tdsInnerConnection = (SqlInternalConnectionTds)InnerConnection;
18551855

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
20592059

20602060
bool result = false;
20612061

2062-
_applyTransientFaultHandling = (!overrides.HasFlag(SqlConnectionOverrides.OpenWithoutRetry) && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
2062+
_applyTransientFaultHandling = (!overrides.HasFlag(SqlConnectionOverrides.OpenWithoutRetry) && retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
20632063

20642064
if (connectionOptions != null &&
20652065
(connectionOptions.Authentication == SqlAuthenticationMethod.SqlPassword ||
@@ -2102,7 +2102,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
21022102
}
21032103

21042104
// Set future transient fault handling based on connection options
2105-
_applyTransientFaultHandling = connectionOptions != null && connectionOptions.ConnectRetryCount > 0;
2105+
_applyTransientFaultHandling = (retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
21062106

21072107
return result;
21082108
}

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs

+4-80
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,6 @@ public async Task PreLoginEncryptionExcludedTest()
5454
Assert.Contains("The instance of SQL Server you attempted to connect to does not support encryption.", ex.Message, StringComparison.OrdinalIgnoreCase);
5555
}
5656

57-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
58-
[InlineData(40613)]
59-
[InlineData(42108)]
60-
[InlineData(42109)]
61-
[PlatformSpecific(TestPlatforms.Windows)]
62-
public async Task TransientFaultTestAsync(uint errorCode)
63-
{
64-
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
65-
SqlConnectionStringBuilder builder = new()
66-
{
67-
DataSource = "localhost," + server.Port,
68-
IntegratedSecurity = true,
69-
Encrypt = SqlConnectionEncryptOption.Optional
70-
};
71-
72-
using SqlConnection connection = new(builder.ConnectionString);
73-
await connection.OpenAsync();
74-
Assert.Equal(ConnectionState.Open, connection.State);
75-
}
76-
7757
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
7858
[InlineData(40613)]
7959
[InlineData(42108)]
@@ -97,70 +77,14 @@ public void TransientFaultTest(uint errorCode)
9777
}
9878
catch (Exception e)
9979
{
80+
if (null != connection)
81+
{
82+
Assert.Equal(ConnectionState.Closed, connection.State);
83+
}
10084
Assert.False(true, e.Message);
10185
}
10286
}
10387

104-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
105-
[InlineData(40613)]
106-
[InlineData(42108)]
107-
[InlineData(42109)]
108-
[PlatformSpecific(TestPlatforms.Windows)]
109-
public async Task TransientFaultDisabledTestAsync(uint errorCode)
110-
{
111-
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
112-
SqlConnectionStringBuilder builder = new()
113-
{
114-
DataSource = "localhost," + server.Port,
115-
IntegratedSecurity = true,
116-
ConnectRetryCount = 0,
117-
Encrypt = SqlConnectionEncryptOption.Optional
118-
};
119-
120-
using SqlConnection connection = new(builder.ConnectionString);
121-
try
122-
{
123-
await connection.OpenAsync();
124-
Assert.False(true, "Connection should not have opened.");
125-
}
126-
catch (SqlException e)
127-
{
128-
// FATAL Error, should result in closed connection.
129-
Assert.Equal(20, e.Class);
130-
Assert.Equal(ConnectionState.Closed, connection.State);
131-
}
132-
}
133-
134-
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
135-
[InlineData(40613)]
136-
[InlineData(42108)]
137-
[InlineData(42109)]
138-
[PlatformSpecific(TestPlatforms.Windows)]
139-
public void TransientFaultDisabledTest(uint errorCode)
140-
{
141-
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
142-
SqlConnectionStringBuilder builder = new()
143-
{
144-
DataSource = "localhost," + server.Port,
145-
IntegratedSecurity = true,
146-
ConnectRetryCount = 0,
147-
Encrypt = SqlConnectionEncryptOption.Optional
148-
};
149-
150-
using SqlConnection connection = new(builder.ConnectionString);
151-
try
152-
{
153-
connection.Open();
154-
Assert.False(true, "Connection should not have opened.");
155-
}
156-
catch (SqlException e)
157-
{
158-
// FATAL Error, should result in closed connection.
159-
Assert.Equal(20, e.Class);
160-
Assert.Equal(ConnectionState.Closed, connection.State);
161-
}
162-
}
163-
16488
[Fact]
16589
public void SqlConnectionDbProviderFactoryTest()
16690
{

src/Microsoft.Data.SqlClient/tests/tools/TDS/TDS.Servers/TransientFaultTDSServer.cs

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ private void Dispose(bool isDisposing)
146146
if (isDisposing)
147147
{
148148
_endpoint?.Stop();
149-
RequestCounter = 0;
150149
}
151150
}
152151
}

0 commit comments

Comments
 (0)