Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add partial packet detection and fixup#2714

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
David-Engel merged 30 commits intodotnet:mainfromWraith2:operation-status-part2
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
30 commits
Select commitHold shift + click to select a range
94b6808
reimplementation of experimental branch on main
Wraith2Nov 4, 2024
53c1139
integrated multiplexer tests and align multiplexer with dev version
Wraith2Oct 29, 2024
3622f9c
address feedback, minor fixes and tuning
Wraith2Jul 24, 2024
d0fd956
add Packet comments
Wraith2Jul 25, 2024
25f0c62
Fix async cancellation and add test coverage for the scenario.
Wraith2Aug 9, 2024
cc694b9
reduce CancelAsyncConnections sensitivity to match main
Wraith2Aug 12, 2024
fb9be3b
make multiplexer not require snapshot to consume partial packets
Wraith2Oct 2, 2024
7f262eb
refine AppendPacketData checks and fix behaviour that was causing it …
Wraith2Oct 15, 2024
67b7762
add more debugging
Wraith2Oct 18, 2024
57c8b86
add debug fail to sanity check in multiplexer to make it clear that i…
Wraith2Oct 23, 2024
b00a379
update multiplexer to deal with multiple sequential packets less than…
Wraith2Oct 24, 2024
352ac25
change multiplexer to deal with trailing partial packets correctly wh…
Wraith2Oct 29, 2024
51137f9
fix rebase conflicts
Wraith2Oct 29, 2024
17ad988
review feedback and misc fix
Wraith2Oct 29, 2024
eae759a
protect missed locations where network reads can happen
Wraith2Oct 30, 2024
29ad90b
fix CheckPacket assertion
Wraith2Oct 31, 2024
5d3f8a6
add try catch around pending read to align with others
Wraith2Nov 4, 2024
36cdd88
Merge branch 'main' of https://github.com/dotnet/SqlClient into opera…
David-EngelNov 8, 2024
433ccf7
Merge branch 'main' of https://github.com/dotnet/SqlClient into opera…
David-EngelDec 18, 2024
c65da55
Apply suggestions from code review
David-EngelDec 18, 2024
b4460ec
Fix merge error
David-EngelDec 18, 2024
80cbb6e
add DumpBuffer function description and format code
Wraith2Dec 27, 2024
bb4fa9e
review feedback 2
Wraith2Dec 31, 2024
79f9fbc
move Packet disposal to debug only
Wraith2Jan 3, 2025
d31e908
review feedback 3
Wraith2Jan 7, 2025
429b7ac
review feedback 4
Wraith2Jan 17, 2025
11dd84e
add app context switched behaviour to allow reverting to previous pro…
Wraith2Jan 19, 2025
7684861
revirew feedback 5
Wraith2Jan 31, 2025
cd1e025
fix tests build
Wraith2Jan 31, 2025
3ed9c83
fix netfx builds
Wraith2Feb 7, 2025
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
PrevPrevious commit
NextNext commit
add app context switched behaviour to allow reverting to previous pro…
…cess sni.
  • Loading branch information
@Wraith2
Wraith2 committedJan 19, 2025
commit11dd84e6b529a69576ffdd3451d90fb1615e9409
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,6 +20,7 @@ private enum Tristate : byte
internal const string SuppressInsecureTLSWarningString = @"Switch.Microsoft.Data.SqlClient.SuppressInsecureTLSWarning";
internal const string UseMinimumLoginTimeoutString = @"Switch.Microsoft.Data.SqlClient.UseOneSecFloorInTimeoutCalculationDuringLogin";
internal const string LegacyVarTimeZeroScaleBehaviourString = @"Switch.Microsoft.Data.SqlClient.LegacyVarTimeZeroScaleBehaviour";
internal const string UseCompatibilityProcessSniString = @"Switch.Microsoft.Data.SqlClient.UseCompatibilityProcessSni";

// this field is accessed through reflection in tests and should not be renamed or have the type changed without refactoring NullRow related tests
private static Tristate s_legacyRowVersionNullBehavior;
Expand All@@ -28,6 +29,7 @@ private enum Tristate : byte
private static Tristate s_useMinimumLoginTimeout;
// this field is accessed through reflection in Microsoft.Data.SqlClient.Tests.SqlParameterTests and should not be renamed or have the type changed without refactoring related tests
private static Tristate s_legacyVarTimeZeroScaleBehaviour;
private static Tristate s_useCompatProcessSni;

#if NET
static LocalAppContextSwitches()
Expand DownExpand Up@@ -83,6 +85,24 @@ public static bool DisableTNIRByDefault
}
}
#endif
public static bool UseCompatibilityProcessSni
{
get
{
if (s_useCompatProcessSni == Tristate.NotInitialized)
{
if (AppContext.TryGetSwitch(UseCompatibilityProcessSniString, out bool returnedValue) && returnedValue)
{
s_useCompatProcessSni = Tristate.True;
}
else
{
s_useCompatProcessSni = Tristate.False;
}
}
return s_useCompatProcessSni == Tristate.True;
}
}

/// <summary>
/// When using Encrypt=false in the connection string, a security warning is output to the console if the TLS version is 1.2 or lower.
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,12 @@ partial class TdsParserStateObject

public void ProcessSniPacket(PacketHandle packet, uint error)
{
if (LocalAppContextSwitches.UseCompatibilityProcessSni)
{
ProcessSniPacketCompat(packet, error);
return;
}

if (error != 0)
{
if ((_parser.State == TdsParserState.Closed) || (_parser.State == TdsParserState.Broken))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Consider_parser.State is TdsParserState.Closed or TdsParserState.Broken

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This falls into the category of maintaining consistent style. The change wouldn't improve functionality and would leave us with files in the solution using different syntax to do the same thing which can cause you not to be able to find them or have to mentally determine that both syntaxes mean the same thing.

If we're going to make this change I'd rather do it in a dedicated style update PR. I don't object to the new syntax I just think we should be consistent.

Expand DownExpand Up@@ -488,5 +494,66 @@ private static bool SetupRemainderPacket(Packet packet)

return containsFullPacket;
}


public void ProcessSniPacketCompat(PacketHandle packet, uint error)
{
if (error != 0)
{
if ((_parser.State == TdsParserState.Closed) || (_parser.State == TdsParserState.Broken))
{
// Do nothing with callback if closed or broken and error not 0 - callback can occur
// after connection has been closed. PROBLEM IN NETLIB - DESIGN FLAW.
return;
}

AddError(_parser.ProcessSNIError(this));
AssertValidState();
}
else
{
uint dataSize = 0;

uint getDataError =
#if NETFRAMEWORK
SniNativeWrapper.
#endif
SNIPacketGetData(packet, _inBuff, ref dataSize);

if (getDataError == TdsEnums.SNI_SUCCESS)
{
if (_inBuff.Length < dataSize)
{
Debug.Assert(true, "Unexpected dataSize on Read");
throw SQL.InvalidInternalPacketSize(StringsHelper.GetString(Strings.SqlMisc_InvalidArraySizeMessage));
}

_lastSuccessfulIOTimer._value = DateTime.UtcNow.Ticks;
_inBytesRead = (int)dataSize;
_inBytesUsed = 0;

if (_snapshot != null)
{
_snapshot.AppendPacketData(_inBuff, _inBytesRead);
if (_snapshotStatus != SnapshotStatus.NotActive)
{
_snapshot.MoveNext();
#if DEBUG
_snapshot.AssertCurrent();
#endif
}
}

SniReadStatisticsAndTracing();
SqlClientEventSource.Log.TryAdvancedTraceBinEvent("TdsParser.ReadNetworkPacketAsyncCallback | INFO | ADV | State Object Id {0}, Packet read. In Buffer: {1}, In Bytes Read: {2}", ObjectID, _inBuff, _inBytesRead);

AssertValidState();
}
else
{
throw SQL.ParsingError(ParsingErrorState.ProcessSniPacketFailed);
}
}
}
}
}
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,6 +14,7 @@ public class LocalAppContextSwitchesTests
[InlineData("LegacyRowVersionNullBehavior", false)]
[InlineData("MakeReadAsyncBlocking", false)]
[InlineData("UseMinimumLoginTimeout", true)]
[InlineData("UseCompatibilityProcessSni", false)]
public void DefaultSwitchValue(string property, bool expectedDefaultValue)
{
var switchesType = typeof(SqlCommand).Assembly.GetType("Microsoft.Data.SqlClient.LocalAppContextSwitches");
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,20 @@ namespace Microsoft.Data.SqlClient.Tests
{
public class MultiplexerTests
{
public static bool IsUsingCompatibilityProcessSni
{
get
{
if (AppContext.TryGetSwitch(@"Switch.Microsoft.Data.SqlClient.UseCompatibilityProcessSni", out bool foundValue))
{
return foundValue;
}
return false;
}
}

public static bool IsUsingModernProcessSni => !IsUsingCompatibilityProcessSni;

[ExcludeFromCodeCoverage]
public static IEnumerable<object[]> IsAsync()
{
Expand All@@ -26,8 +40,8 @@ public static IEnumerable<object[]> IsAsync()

[ExcludeFromCodeCoverage]
public static IEnumerable<object[]> OnlyAsync() { yield return new object[] { true }; }

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void PassThroughSinglePacket(bool isAsync)
{
int dataSize = 20;
Expand All@@ -42,7 +56,7 @@ public static void PassThroughSinglePacket(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void PassThroughMultiplePacket(bool isAsync)
{
int dataSize = 40;
Expand All@@ -56,7 +70,7 @@ public static void PassThroughMultiplePacket(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void PassThroughMultiplePacketWithShortEnd(bool isAsync)
{
int dataSize = 40;
Expand All@@ -70,7 +84,7 @@ public static void PassThroughMultiplePacketWithShortEnd(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void ReconstructSinglePacket(bool isAsync)
{
int dataSize = 4;
Expand All@@ -85,7 +99,7 @@ public static void ReconstructSinglePacket(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void Reconstruct2Packets_Part_PartFull(bool isAsync)
{
int dataSize = 4;
Expand All@@ -104,7 +118,7 @@ public static void Reconstruct2Packets_Part_PartFull(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void Reconstruct2Packets_Full_FullPart_Part(bool isAsync)
{
int dataSize = 30;
Expand All@@ -123,7 +137,7 @@ public static void Reconstruct2Packets_Full_FullPart_Part(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void ReconstructMultiplePacketSequence(bool isAsync)
{
int dataSize = 40;
Expand All@@ -143,7 +157,7 @@ public static void ReconstructMultiplePacketSequence(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void ReconstructMultiplePacketSequenceWithShortEnd(bool isAsync)
{
int dataSize = 40;
Expand All@@ -162,7 +176,7 @@ public static void ReconstructMultiplePacketSequenceWithShortEnd(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Theory, MemberData(nameof(IsAsync))]
[ConditionalTheory(nameof(IsUsingModernProcessSni)), MemberData(nameof(IsAsync))]
public static void Reconstruct3Packets_PartPartPart(bool isAsync)
{
int dataSize = 62;
Expand All@@ -178,7 +192,7 @@ public static void Reconstruct3Packets_PartPartPart(bool isAsync)
ComparePacketLists(dataSize, expected, output);
}

[Fact]
[ConditionalFact(nameof(IsUsingModernProcessSni))]
public static void TrailingPartialPacketInSnapshotNotDuplicated()
{
int dataSize = 120;
Expand All@@ -197,7 +211,7 @@ public static void TrailingPartialPacketInSnapshotNotDuplicated()
ComparePacketLists(dataSize, expected, output);
}

[Fact]
[ConditionalFact(nameof(IsUsingModernProcessSni))]
public static void BetweenAsyncAttentionPacket()
{
int dataSize = 120;
Expand All@@ -222,7 +236,7 @@ public static void BetweenAsyncAttentionPacket()

}

[Fact]
[ConditionalFact(nameof(IsUsingModernProcessSni))]
public static void MultipleFullPacketsInRemainderAreSplitCorrectly()
{
int dataSize = 800 - TdsEnums.HEADER_LEN;
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp