Skip to content

Commit 0d2807f

Browse files
committed
Revert "Fix SqlCached buffer async read with continue edge case. (#3329)"
This reverts commit c3857b1.
1 parent 37db170 commit 0d2807f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
3939
{
4040
buffer = null;
4141

42-
(bool isAvailable, bool isStarting, _) = stateObj.GetSnapshotStatuses();
42+
(bool isAvailable, bool isStarting, bool isContinuing) = stateObj.GetSnapshotStatuses();
4343

4444
List<byte[]> cachedBytes = null;
4545
if (isAvailable)
4646
{
4747
cachedBytes = stateObj.TryTakeSnapshotStorage() as List<byte[]>;
48-
if (isStarting)
48+
if (cachedBytes != null && !isStarting && !isContinuing)
4949
{
50-
cachedBytes = null;
50+
stateObj.SetSnapshotStorage(null);
5151
}
5252
}
5353

@@ -56,13 +56,15 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
5656
cachedBytes = new List<byte[]>();
5757
}
5858

59+
5960
// the very first length is already read.
6061
TdsOperationStatus result = parser.TryPlpBytesLeft(stateObj, out ulong plplength);
6162
if (result != TdsOperationStatus.Done)
6263
{
6364
return result;
6465
}
6566

67+
6668
// For now we only handle Plp data from the parser directly.
6769
Debug.Assert(metadata.metaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
6870
do
@@ -103,7 +105,10 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
103105

104106
if (returnAfterAdd)
105107
{
106-
stateObj.SetSnapshotStorage(cachedBytes);
108+
if (isStarting || isContinuing)
109+
{
110+
stateObj.SetSnapshotStorage(cachedBytes);
111+
}
107112
return result;
108113
}
109114

0 commit comments

Comments
 (0)