Skip to content

Commit

Permalink
Revert "Fix | Take out the ignoreSniOpenTimeout in open connection (d…
Browse files Browse the repository at this point in the history
…otnet#2067)"

This reverts commit 7314307.

# Conflicts:
#	src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs
  • Loading branch information
DavoudEshtehari committed Jul 21, 2023
1 parent efbf329 commit 02ffcb1
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private static bool IsErrorStatus(SecurityStatusPalErrorCode errorCode)
/// Create a SNI connection handle
/// </summary>
/// <param name="fullServerName">Full server name from connection string</param>
/// <param name="ignoreSniOpenTimeout">Ignore open timeout</param>
/// <param name="timerExpire">Timer expiration</param>
/// <param name="instanceName">Instance name</param>
/// <param name="spnBuffer">SPN</param>
Expand All @@ -147,6 +148,7 @@ private static bool IsErrorStatus(SecurityStatusPalErrorCode errorCode)
/// <returns>SNI handle</returns>
internal static SNIHandle CreateConnectionHandle(
string fullServerName,
bool ignoreSniOpenTimeout,
long timerExpire,
out byte[] instanceName,
ref byte[][] spnBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,7 @@ private void LoginNoFailover(ServerInfo serverInfo,
AttemptOneLogin(serverInfo,
newPassword,
newSecurePassword,
!connectionOptions.MultiSubnetFailover, // ignore timeout for SniOpen call unless MSF
connectionOptions.MultiSubnetFailover ? intervalTimer : timeout);

if (connectionOptions.MultiSubnetFailover && null != ServerProvidedFailOverPartner)
Expand Down Expand Up @@ -1781,6 +1782,7 @@ TimeoutTimer timeout
currentServerInfo,
newPassword,
newSecurePassword,
false, // Use timeout in SniOpen
intervalTimer,
withFailover: true
);
Expand Down Expand Up @@ -1908,6 +1910,7 @@ private void AttemptOneLogin(
ServerInfo serverInfo,
string newPassword,
SecureString newSecurePassword,
bool ignoreSniOpenTimeout,
TimeoutTimer timeout,
bool withFailover = false)
{
Expand All @@ -1918,6 +1921,7 @@ private void AttemptOneLogin(

_parser.Connect(serverInfo,
this,
ignoreSniOpenTimeout,
timeout.LegacyTimerExpire,
ConnectionOptions,
withFailover);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ internal void ProcessPendingAck(TdsParserStateObject stateObj)
internal void Connect(
ServerInfo serverInfo,
SqlInternalConnectionTds connHandler,
bool ignoreSniOpenTimeout,
long timerExpire,
SqlConnectionString connectionOptions,
bool withFailover)
Expand Down Expand Up @@ -444,6 +445,7 @@ internal void Connect(
// AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
_physicalStateObj.CreatePhysicalSNIHandle(
serverInfo.ExtendedServerName,
ignoreSniOpenTimeout,
timerExpire,
out instanceName,
ref _sniSpnBuffer,
Expand Down Expand Up @@ -542,6 +544,7 @@ internal void Connect(

_physicalStateObj.CreatePhysicalSNIHandle(
serverInfo.ExtendedServerName,
ignoreSniOpenTimeout,
timerExpire, out instanceName,
ref _sniSpnBuffer,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ private void ResetCancelAndProcessAttention()

internal abstract void CreatePhysicalSNIHandle(
string serverName,
bool ignoreSniOpenTimeout,
long timerExpire,
out byte[] instanceName,
ref byte[][] spnBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected override uint SNIPacketGetData(PacketHandle packet, byte[] inBuff, ref

internal override void CreatePhysicalSNIHandle(
string serverName,
bool ignoreSniOpenTimeout,
long timerExpire,
out byte[] instanceName,
ref byte[][] spnBuffer,
Expand All @@ -97,7 +98,7 @@ internal override void CreatePhysicalSNIHandle(
string hostNameInCertificate,
string serverCertificateFilename)
{
SNIHandle? sessionHandle = SNIProxy.CreateConnectionHandle(serverName, timerExpire, out instanceName, ref spnBuffer, serverSPN,
SNIHandle? sessionHandle = SNIProxy.CreateConnectionHandle(serverName, ignoreSniOpenTimeout, timerExpire, out instanceName, ref spnBuffer, serverSPN,
flushCache, async, parallel, isIntegratedSecurity, iPAddressPreference, cachedFQDN, ref pendingDNSInfo, tlsFirst,
hostNameInCertificate, serverCertificateFilename);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private SNINativeMethodWrapper.ConsumerInfo CreateConsumerInfo(bool async)

internal override void CreatePhysicalSNIHandle(
string serverName,
bool ignoreSniOpenTimeout,
long timerExpire,
out byte[] instanceName,
ref byte[][] spnBuffer,
Expand Down Expand Up @@ -198,7 +199,7 @@ internal override void CreatePhysicalSNIHandle(
SQLDNSInfo cachedDNSInfo;
bool ret = SQLFallbackDNSCache.Instance.GetDNSInfo(cachedFQDN, out cachedDNSInfo);

_sessionHandle = new SNIHandle(myInfo, serverName, spnBuffer[0], checked((int)timeout), out instanceName,
_sessionHandle = new SNIHandle(myInfo, serverName, spnBuffer[0], ignoreSniOpenTimeout, checked((int)timeout), out instanceName,
flushCache, !async, fParallel, ipPreference, cachedDNSInfo, hostNameInCertificate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,7 @@ private void LoginNoFailover(ServerInfo serverInfo, string newPassword, SecureSt
AttemptOneLogin(serverInfo,
newPassword,
newSecurePassword,
!isParallel, // ignore timeout for SniOpen call unless MSF , and TNIR
attemptOneLoginTimeout,
isFirstTransparentAttempt: isFirstTransparentAttempt,
disableTnir: disableTnir);
Expand Down Expand Up @@ -2136,6 +2137,7 @@ TimeoutTimer timeout
currentServerInfo,
newPassword,
newSecurePassword,
false, // Use timeout in SniOpen
intervalTimer,
withFailover: true
);
Expand Down Expand Up @@ -2173,6 +2175,7 @@ TimeoutTimer timeout
currentServerInfo,
newPassword,
newSecurePassword,
false, // Use timeout in SniOpen
intervalTimer,
withFailover: true
);
Expand Down Expand Up @@ -2290,7 +2293,7 @@ private void ResolveExtendedServerName(ServerInfo serverInfo, bool aliasLookup,
}

// Common code path for making one attempt to establish a connection and log in to server.
private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, SecureString newSecurePassword, TimeoutTimer timeout, bool withFailover = false, bool isFirstTransparentAttempt = true, bool disableTnir = false)
private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, SecureString newSecurePassword, bool ignoreSniOpenTimeout, TimeoutTimer timeout, bool withFailover = false, bool isFirstTransparentAttempt = true, bool disableTnir = false)
{
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlInternalConnectionTds.AttemptOneLogin|ADV> {0}, timout={1}[msec], server={2}", ObjectID, timeout.MillisecondsRemaining, serverInfo.ExtendedServerName);

Expand All @@ -2300,6 +2303,7 @@ private void AttemptOneLogin(ServerInfo serverInfo, string newPassword, SecureSt

_parser.Connect(serverInfo,
this,
ignoreSniOpenTimeout,
timeout.LegacyTimerExpire,
ConnectionOptions,
withFailover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ internal void ProcessPendingAck(TdsParserStateObject stateObj)

internal void Connect(ServerInfo serverInfo,
SqlInternalConnectionTds connHandler,
bool ignoreSniOpenTimeout,
long timerExpire,
SqlConnectionString connectionOptions,
bool withFailover,
Expand Down Expand Up @@ -639,6 +640,7 @@ internal void Connect(ServerInfo serverInfo,

_physicalStateObj.CreatePhysicalSNIHandle(
serverInfo.ExtendedServerName,
ignoreSniOpenTimeout,
timerExpire,
out instanceName,
_sniSpnBuffer,
Expand Down Expand Up @@ -744,6 +746,7 @@ internal void Connect(ServerInfo serverInfo,
_physicalStateObj.SniContext = SniContext.Snix_Connect;
_physicalStateObj.CreatePhysicalSNIHandle(
serverInfo.ExtendedServerName,
ignoreSniOpenTimeout,
timerExpire,
out instanceName,
_sniSpnBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ private SNINativeMethodWrapper.ConsumerInfo CreateConsumerInfo(bool async)

internal void CreatePhysicalSNIHandle(
string serverName,
bool ignoreSniOpenTimeout,
long timerExpire,
out byte[] instanceName,
byte[] spnBuffer,
Expand Down Expand Up @@ -317,7 +318,7 @@ internal void CreatePhysicalSNIHandle(

_ = SQLFallbackDNSCache.Instance.GetDNSInfo(cachedFQDN, out SQLDNSInfo cachedDNSInfo);

_sessionHandle = new SNIHandle(myInfo, serverName, spnBuffer, checked((int)timeout),
_sessionHandle = new SNIHandle(myInfo, serverName, spnBuffer, ignoreSniOpenTimeout, checked((int)timeout),
out instanceName, flushCache, !async, fParallel, transparentNetworkResolutionState, totalTimeout,
ipPreference, cachedDNSInfo, hostNameInCertificate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ internal SNIHandle(
SNINativeMethodWrapper.ConsumerInfo myInfo,
string serverName,
byte[] spnBuffer,
bool ignoreSniOpenTimeout,
int timeout,
out byte[] instanceName,
bool flushCache,
Expand All @@ -173,14 +174,13 @@ internal SNIHandle(
{
_fSync = fSync;
instanceName = new byte[256]; // Size as specified by netlibs.
// Option ignoreSniOpenTimeout is no longer available
//if (ignoreSniOpenTimeout)
//{
// // UNDONE: ITEM12001110 (DB Mirroring Reconnect) Old behavior of not truly honoring timeout presevered
// // for non-failover scenarios to avoid breaking changes as part of a QFE. Consider fixing timeout
// // handling in next full release and removing ignoreSniOpenTimeout parameter.
// timeout = Timeout.Infinite; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE
//}
if (ignoreSniOpenTimeout)
{
// UNDONE: ITEM12001110 (DB Mirroring Reconnect) Old behavior of not truly honoring timeout presevered
// for non-failover scenarios to avoid breaking changes as part of a QFE. Consider fixing timeout
// handling in next full release and removing ignoreSniOpenTimeout parameter.
timeout = Timeout.Infinite; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE
}

#if NETFRAMEWORK
int transparentNetworkResolutionStateNo = (int)transparentNetworkResolutionState;
Expand Down

0 comments on commit 02ffcb1

Please sign in to comment.