From 9952f154582106b8de5f5387ac2c72c257bd335c Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Sat, 2 Aug 2025 00:14:32 -0700 Subject: [PATCH 1/3] Disable packet multiplexing design by default --- .../Data/SqlClient/LocalAppContextSwitches.cs | 13 ++++++++----- .../tests/FunctionalTests/MultiplexerTests.cs | 2 +- .../Data/SqlClient/LocalAppContextSwitchesTest.cs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs index ee5d088dc4..380236f89b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs @@ -69,8 +69,9 @@ static LocalAppContextSwitches() /// /// In TdsParser the ProcessSni function changed significantly when the packet /// multiplexing code needed for high speed multi-packet column values was added. - /// In case of compatibility problems this switch will change TdsParser to use - /// the previous version of the function. + /// The switch is enabled by default and retains the old ProcessSni design. + /// Use this switch to enable experimental design that uses the new ProcessSni + /// behavior using the packet multiplexer. /// public static bool UseCompatibilityProcessSni { @@ -78,7 +79,9 @@ public static bool UseCompatibilityProcessSni { if (s_useCompatibilityProcessSni == Tristate.NotInitialized) { - if (AppContext.TryGetSwitch(UseCompatibilityProcessSniString, out bool returnedValue) && returnedValue) + // Check if the switch has been set by the AppContext switch directly + // If it has not been set, we default to true. + if (!AppContext.TryGetSwitch(UseCompatibilityProcessSniString, out bool returnedValue) || returnedValue) { s_useCompatibilityProcessSni = Tristate.True; } @@ -95,7 +98,7 @@ public static bool UseCompatibilityProcessSni /// In TdsParser the async multi-packet column value fetch behaviour is capable of /// using a continue snapshot state in addition to the original replay from start /// logic. - /// This switch disables use of the continue snapshot state. This switch will always + /// This switch disables use of the continue snapshot state and is enabled by default. This switch will always /// return true if is enabled because the /// continue state is not stable without the multiplexer. /// @@ -114,7 +117,7 @@ public static bool UseCompatibilityAsyncBehaviour if (s_useCompatibilityAsyncBehaviour == Tristate.NotInitialized) { - if (AppContext.TryGetSwitch(UseCompatibilityAsyncBehaviourString, out bool returnedValue) && returnedValue) + if (!AppContext.TryGetSwitch(UseCompatibilityAsyncBehaviourString, out bool returnedValue) || returnedValue) { s_useCompatibilityAsyncBehaviour = Tristate.True; } diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs index 288586fb17..efa7962d28 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/MultiplexerTests.cs @@ -25,7 +25,7 @@ public static bool IsUsingCompatibilityProcessSni { return foundValue; } - return false; + return true; // Default to true if the switch is not set } } diff --git a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs index ec60f0d3cd..c28fe18978 100644 --- a/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/LocalAppContextSwitchesTest.cs @@ -23,8 +23,8 @@ public void TestDefaultAppContextSwitchValues() Assert.False(LocalAppContextSwitches.MakeReadAsyncBlocking); Assert.True(LocalAppContextSwitches.UseMinimumLoginTimeout); Assert.True(LocalAppContextSwitches.LegacyVarTimeZeroScaleBehaviour); - Assert.False(LocalAppContextSwitches.UseCompatibilityProcessSni); - Assert.False(LocalAppContextSwitches.UseCompatibilityAsyncBehaviour); + Assert.True(LocalAppContextSwitches.UseCompatibilityProcessSni); + Assert.True(LocalAppContextSwitches.UseCompatibilityAsyncBehaviour); Assert.False(LocalAppContextSwitches.UseConnectionPoolV2); Assert.False(LocalAppContextSwitches.TruncateScaledDecimal); #if NETFRAMEWORK From bcf12814b9d49f06dbe738d4b082d6ffffbf1d40 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Sat, 2 Aug 2025 00:26:37 -0700 Subject: [PATCH 2/3] Update comments --- src/Directory.Packages.props | 2 +- .../Data/SqlClient/LocalAppContextSwitches.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index f897e55f77..6d6faf58f5 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -14,7 +14,7 @@ - + diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs index 380236f89b..f546b0436b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs @@ -67,11 +67,11 @@ static LocalAppContextSwitches() #endif /// - /// In TdsParser the ProcessSni function changed significantly when the packet + /// In TdsParser, the ProcessSni function changed significantly when the packet /// multiplexing code needed for high speed multi-packet column values was added. - /// The switch is enabled by default and retains the old ProcessSni design. - /// Use this switch to enable experimental design that uses the new ProcessSni - /// behavior using the packet multiplexer. + /// When this switch is set to true (the default), the old ProcessSni design is used. + /// When this switch is set to false, the new experimental ProcessSni behavior using + /// the packet multiplexer is enabled. /// public static bool UseCompatibilityProcessSni { @@ -95,12 +95,12 @@ public static bool UseCompatibilityProcessSni } /// - /// In TdsParser the async multi-packet column value fetch behaviour is capable of - /// using a continue snapshot state in addition to the original replay from start - /// logic. - /// This switch disables use of the continue snapshot state and is enabled by default. This switch will always - /// return true if is enabled because the - /// continue state is not stable without the multiplexer. + /// In TdsParser, the async multi-packet column value fetch behavior can use a continue snapshot state + /// for improved efficiency. When this switch is enabled (the default), the driver preserves the legacy + /// compatibility behavior, which does not use the continue snapshot state. When disabled, the new behavior + /// using the continue snapshot state is enabled. This switch will always return true if + /// is enabled, because the continue state is not stable without + /// the multiplexer. /// public static bool UseCompatibilityAsyncBehaviour { From 5b75d816f3e95e1f401939bb5fee697e08fa5684 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Sat, 2 Aug 2025 00:49:27 -0700 Subject: [PATCH 3/3] Revert for this PR --- src/Directory.Packages.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 6d6faf58f5..f897e55f77 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -14,7 +14,7 @@ - +