Skip to content

Commit

Permalink
[5.2.1] | Revert "Merged PR 4035: [5.1.2] | Fix Transient fault handl…
Browse files Browse the repository at this point in the history
…ing issue with OpenAsync (#1983)"

This reverts commit 80d1f47.

# Conflicts:
#	src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs
  • Loading branch information
DavoudEshtehari committed May 16, 2024
1 parent 82be9a6 commit 908091f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
}
}

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

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

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

var tdsInnerConnection = (SqlInternalConnectionTds)InnerConnection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec

bool result = false;

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

if (connectionOptions != null &&
(connectionOptions.Authentication == SqlAuthenticationMethod.SqlPassword ||
Expand Down Expand Up @@ -2187,7 +2187,7 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry, SqlConnec
}

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

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,6 @@ public async Task PreLoginEncryptionExcludedTest()
Assert.Contains("The instance of SQL Server you attempted to connect to does not support encryption.", ex.Message, StringComparison.OrdinalIgnoreCase);
}

[ConditionalTheory(typeof(TestUtility), nameof(TestUtility.IsNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
[PlatformSpecific(TestPlatforms.Windows)]
public async Task TransientFaultTestAsync(uint errorCode)
{
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
SqlConnectionStringBuilder builder = new()
{
DataSource = "localhost," + server.Port,
IntegratedSecurity = true,
Encrypt = SqlConnectionEncryptOption.Optional
};

using SqlConnection connection = new(builder.ConnectionString);
await connection.OpenAsync();
Assert.Equal(ConnectionState.Open, connection.State);
}

[ConditionalTheory(typeof(TestUtility), nameof(TestUtility.IsNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
Expand All @@ -100,54 +80,14 @@ public void TransientFaultTest(uint errorCode)
}
catch (Exception e)
{
if (null != connection)
{
Assert.Equal(ConnectionState.Closed, connection.State);
}
Assert.Fail(e.Message);
}
}

[ConditionalTheory(typeof(TestUtility), nameof(TestUtility.IsNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
[PlatformSpecific(TestPlatforms.Windows)]
public void TransientFaultDisabledTestAsync(uint errorCode)
{
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
SqlConnectionStringBuilder builder = new()
{
DataSource = "localhost," + server.Port,
IntegratedSecurity = true,
ConnectRetryCount = 0,
Encrypt = SqlConnectionEncryptOption.Optional
};

using SqlConnection connection = new(builder.ConnectionString);
Task<SqlException> e = Assert.ThrowsAsync<SqlException>(async () => await connection.OpenAsync());
Assert.Equal(20, e.Result.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}

[ConditionalTheory(typeof(TestUtility), nameof(TestUtility.IsNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
[PlatformSpecific(TestPlatforms.Windows)]
public void TransientFaultDisabledTest(uint errorCode)
{
using TransientFaultTDSServer server = TransientFaultTDSServer.StartTestServer(true, true, errorCode);
SqlConnectionStringBuilder builder = new()
{
DataSource = "localhost," + server.Port,
IntegratedSecurity = true,
ConnectRetryCount = 0,
Encrypt = SqlConnectionEncryptOption.Optional
};

using SqlConnection connection = new(builder.ConnectionString);
SqlException e = Assert.Throws<SqlException>(() => connection.Open());
Assert.Equal(20, e.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}

[Fact]
public void SqlConnectionDbProviderFactoryTest()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ private void Dispose(bool isDisposing)
if (isDisposing)
{
_endpoint?.Stop();
RequestCounter = 0;
}
}
}
Expand Down

0 comments on commit 908091f

Please sign in to comment.