Skip to content

Commit cbfc005

Browse files
committed
fix
1 parent 60270e5 commit cbfc005

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

src/libraries/System.Text.Json/src/Resources/Strings.resx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,13 @@
830830
<data name="DuplicatePropertiesNotAllowed_JsonPropertyInfo" xml:space="preserve">
831831
<value>Duplicate property '{0}' encountered during deserialization of type '{1}'.</value>
832832
</data>
833-
<data name="DuplicatePropertiesNotAllowed_NameSpan" xml:space="preserve">
833+
<data name="DuplicatePropertiesNotAllowed_NameSpan" xml:space="preserve">
834834
<value>Duplicate property '{0}' encountered during deserialization.</value>
835835
</data>
836836
<data name="DuplicatePropertiesNotAllowed" xml:space="preserve">
837837
<value>Duplicate properties not allowed during deserialization.</value>
838838
</data>
839-
</root>
839+
<data name="PipeReaderCanceled" xml:space="preserve">
840+
<value>PipeReader.ReadAsync was canceled.</value>
841+
</data>
842+
</root>

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.Pipe.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public static partial class JsonSerializer
330330
ReadStack readStack = default;
331331
readStack.Initialize(listTypeInfo, supportContinuation: true);
332332
JsonReaderState jsonReaderState = new(readerOptions);
333-
PipeReadBufferState bufferState = default;
333+
PipeReadBufferState bufferState = new(utf8Json);
334334

335335
try
336336
{

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/PipeReadBufferState.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ public async ValueTask<PipeReadBufferState> ReadAsync(PipeReader utf8Json, Cance
6060
ReadResult readResult = await _utf8Json.ReadAtLeastAsync(minBufferSize, cancellationToken).ConfigureAwait(false);
6161

6262
bufferState._sequence = readResult.Buffer;
63-
bufferState._isFinalBlock = readResult.IsCompleted || readResult.IsCanceled;
63+
bufferState._isFinalBlock = readResult.IsCompleted;
6464
bufferState.ProcessReadBytes();
6565

66+
if (readResult.IsCanceled)
67+
{
68+
ThrowHelper.ThrowOperationCanceledException_PipeReadCanceled();
69+
}
70+
6671
return bufferState;
6772
}
6873

src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.Serialization.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,12 @@ public static void ThrowOperationCanceledException_PipeWriteCanceled()
979979
throw new OperationCanceledException(SR.PipeWriterCanceled);
980980
}
981981

982+
[DoesNotReturn]
983+
public static void ThrowOperationCanceledException_PipeReadCanceled()
984+
{
985+
throw new OperationCanceledException(SR.PipeReaderCanceled);
986+
}
987+
982988
[DoesNotReturn]
983989
public static void ThrowInvalidOperationException_PipeWriterDoesNotImplementUnflushedBytes(PipeWriter pipeWriter)
984990
{

src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Pipe.ReadTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ public async Task CancelPendingReadThrows()
9494
Task readTask = Serializer.DeserializeWrapper<int>(pipe.Reader);
9595
pipe.Reader.CancelPendingRead();
9696

97-
await Assert.ThrowsAsync<JsonException>(async () => await readTask);
97+
OperationCanceledException ex = await Assert.ThrowsAsync<OperationCanceledException>(async () => await readTask);
98+
Assert.Equal("PipeReader.ReadAsync was canceled.", ex.Message);
9899

99100
// Clean up
100101
pipe.Writer.Complete();

0 commit comments

Comments
 (0)