Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9d8e214
Revert 1af7327454f9cafbf3aaaa8b3d615489aad480ab
mdaigle Aug 5, 2025
4763951
Revert "Fix TryReadPlpBytes throws ArgumentException (#3470) (#3474)"
mdaigle Aug 5, 2025
93a86d0
Revert 44762d90913ac93ffd78f58a0d87e59cf3d65a43
mdaigle Aug 5, 2025
2c83dc9
Revert "Improve async string perf and fix reading chars with initial …
mdaigle Aug 5, 2025
37db170
Revert "Refine handling of moving between replay and continue states …
mdaigle Aug 5, 2025
0d2807f
Revert "Fix SqlCached buffer async read with continue edge case. (#33…
mdaigle Aug 5, 2025
7fb7041
Revert "Add `async` snapshot continue capability for multipacket fiel…
mdaigle Aug 5, 2025
006cd12
Revert "Add partial packet detection and fixup (#2714)"
mdaigle Aug 6, 2025
40c19a6
Remove methods previously moved to common file.
mdaigle Aug 6, 2025
6cea8df
Supply byte buffer to vector read.
mdaigle Aug 6, 2025
11d3b43
Minor compilation fixes that were missed in the reverts.
mdaigle Aug 6, 2025
f6691f4
Remove partial packet context switch helpers.
mdaigle Aug 6, 2025
6944ab6
Remove accidental duplication of SqlDataReader
mdaigle Aug 8, 2025
1ac8090
Revert len change
mdaigle Aug 11, 2025
a4ac40a
Undo buff rental in netfx to simplify 6.0 diff.
mdaigle Aug 11, 2025
73a3a19
Fix missed rented buff code.
mdaigle Aug 11, 2025
865b774
Merge branch 'release/6.1' of github.com:dotnet/SqlClient into dev/md…
mdaigle Aug 12, 2025
089e72c
Merge branch 'release/6.1' into dev/mdaigle/revert-partial-packet
cheenamalhotra Aug 13, 2025
9a6817f
Merge branch 'release/6.1' of github.com:dotnet/SqlClient into dev/md…
mdaigle Aug 13, 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
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\OnChangedEventHandler.cs">
<Link>Microsoft\Data\SqlClient\OnChangedEventHandler.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Packet.cs">
<Link>Microsoft\Data\SqlClient\Packet.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\ParameterPeekAheadValue.cs">
<Link>Microsoft\Data\SqlClient\ParameterPeekAheadValue.cs</Link>
</Compile>
Expand Down Expand Up @@ -762,9 +759,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserStateObject.cs">
<Link>Microsoft\Data\SqlClient\TdsParserStateObject.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserStateObject.Multiplexer.cs">
<Link>Microsoft\Data\SqlClient\TdsParserStateObject.Multiplexer.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserStaticMethods.cs">
<Link>Microsoft\Data\SqlClient\TdsParserStaticMethods.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ internal void PostReadAsyncForMars()

_pMarsPhysicalConObj.IncrementPendingCallbacks();
SessionHandle handle = _pMarsPhysicalConObj.SessionHandle;
// we do not need to consider partial packets when making this read because we
// expect this read to pend. a partial packet should not exist at setup of the
// parser
Debug.Assert(_physicalStateObj.PartialPacket==null);
temp = _pMarsPhysicalConObj.ReadAsync(handle, out error);

Debug.Assert(temp.Type == PacketHandle.NativePointerType, "unexpected packet type when requiring NativePointer");
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,14 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error)
stateObj.SendAttention(mustTakeWriteLock: true);

PacketHandle syncReadPacket = default;
bool readFromNetwork = true;
RuntimeHelpers.PrepareConstrainedRegions();
bool shouldDecrement = false;
try
{
Interlocked.Increment(ref _readingCount);
shouldDecrement = true;
readFromNetwork = !PartialPacketContainsCompletePacket();
if (readFromNetwork)
{
syncReadPacket = ReadSyncOverAsync(stateObj.GetTimeoutRemaining(), out error);
}
else
{
error = TdsEnums.SNI_SUCCESS;
}

syncReadPacket = ReadSyncOverAsync(stateObj.GetTimeoutRemaining(), out error);

Interlocked.Decrement(ref _readingCount);
shouldDecrement = false;
Expand All @@ -195,7 +187,7 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error)
}
else
{
Debug.Assert(!readFromNetwork || !IsValidPacket(syncReadPacket), "unexpected syncReadPacket without corresponding SNIPacketRelease");
Debug.Assert(!IsValidPacket(syncReadPacket), "unexpected syncReadPacket without corresponding SNIPacketRelease");
fail = true; // Subsequent read failed, time to give up.
}
}
Expand All @@ -206,7 +198,7 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error)
Interlocked.Decrement(ref _readingCount);
}

if (readFromNetwork && !IsPacketEmpty(syncReadPacket))
if (!IsPacketEmpty(syncReadPacket))
{
// Be sure to release packet, otherwise it will be leaked by native.
ReleasePacket(syncReadPacket);
Expand Down Expand Up @@ -247,9 +239,60 @@ private void ReadSniError(TdsParserStateObject stateObj, uint error)
AssertValidState();
}

private uint GetSniPacket(PacketHandle packet, ref uint dataSize)
public void ProcessSniPacket(PacketHandle packet, uint error)
{
return SniPacketGetData(packet, _inBuff, ref dataSize);
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 = 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 (_snapshotReplay)
{
_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);
}
}
}

private void SetBufferSecureStrings()
Expand Down Expand Up @@ -321,7 +364,7 @@ public void ReadAsyncCallback(IntPtr key, PacketHandle packet, uint error)
bool processFinallyBlock = true;
try
{
Debug.Assert((packet.Type == 0 && PartialPacketContainsCompletePacket()) || (CheckPacket(packet, source) && source != null), "AsyncResult null on callback");
Debug.Assert(CheckPacket(packet, source) && source != null, "AsyncResult null on callback");

if (_parser.MARSOn)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\OnChangedEventHandler.cs">
<Link>Microsoft\Data\SqlClient\OnChangedEventHandler.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Packet.cs">
<Link>Microsoft\Data\SqlClient\Packet.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\PacketHandle.Windows.cs">
<Link>Microsoft\Data\SqlClient\PacketHandle.Windows.cs</Link>
</Compile>
Expand Down Expand Up @@ -855,9 +852,6 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserStateObject.cs">
<Link>Microsoft\Data\SqlClient\TdsParserStateObject.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserStateObject.Multiplexer.cs">
<Link>Microsoft\Data\SqlClient\TdsParserStateObject.Multiplexer.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Windows.cs">
<Link>Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Windows.cs</Link>
</Compile>
Expand Down
Loading
Loading