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

[5.1.6] | Revert the fix transient fault handling issue with OpenAsync (#1983) #2508

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -1820,7 +1820,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 @@ -1849,7 +1849,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 @@ -2059,7 +2059,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 @@ -2102,7 +2102,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 @@ -7,7 +7,6 @@
using System.Data.Common;
using System.Reflection;
using System.Security;
using System.Threading.Tasks;
using Microsoft.SqlServer.TDS.Servers;
using Xunit;

Expand Down Expand Up @@ -54,26 +53,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(PlatformDetection), nameof(PlatformDetection.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(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
Expand All @@ -97,70 +76,14 @@ public void TransientFaultTest(uint errorCode)
}
catch (Exception e)
{
if (null != connection)
{
Assert.Equal(ConnectionState.Closed, connection.State);
}
Assert.False(true, e.Message);
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))]
[InlineData(40613)]
[InlineData(42108)]
[InlineData(42109)]
[PlatformSpecific(TestPlatforms.Windows)]
public async Task 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);
try
{
await connection.OpenAsync();
Assert.False(true, "Connection should not have opened.");
}
catch (SqlException e)
{
// FATAL Error, should result in closed connection.
Assert.Equal(20, e.Class);
Assert.Equal(ConnectionState.Closed, connection.State);
}
}

[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.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);
try
{
connection.Open();
Assert.False(true, "Connection should not have opened.");
}
catch (SqlException e)
{
// FATAL Error, should result in closed connection.
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
Loading