Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadek Zikmund <radekzikmund@microsoft.com>2022-08-26 11:33:47 +0300
committergithub-actions <github-actions@github.com>2022-09-07 09:43:48 +0300
commitbce2cf10526cc970b83dc87065a4bb3e5dd29b47 (patch)
tree7bc40bc848f6a5131cfcbbd0f1db5d532239f720
parent9dda76511887faec0f5cc65d1e305be839a2dcbc (diff)
Swallow ObjectDisposedException when aborting QuicStream from CancellationActionbackport/pr-74634-to-release/7.0
-rw-r--r--src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
index c11f3029a21..d886ce4288f 100644
--- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
+++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
@@ -70,9 +70,18 @@ public sealed partial class QuicStream
{
CancellationAction = target =>
{
- if (target is QuicStream stream)
+ try
{
- stream.Abort(QuicAbortDirection.Read, stream._defaultErrorCode);
+ if (target is QuicStream stream)
+ {
+ stream.Abort(QuicAbortDirection.Read, stream._defaultErrorCode);
+ }
+ }
+ catch (ObjectDisposedException)
+ {
+ // We collided with a Dispose in another thread. This can happen
+ // when using CancellationTokenSource.CancelAfter.
+ // Ignore the exception
}
}
};
@@ -83,9 +92,18 @@ public sealed partial class QuicStream
{
CancellationAction = target =>
{
- if (target is QuicStream stream)
+ try
+ {
+ if (target is QuicStream stream)
+ {
+ stream.Abort(QuicAbortDirection.Write, stream._defaultErrorCode);
+ }
+ }
+ catch (ObjectDisposedException)
{
- stream.Abort(QuicAbortDirection.Write, stream._defaultErrorCode);
+ // We collided with a Dispose in another thread. This can happen
+ // when using CancellationTokenSource.CancelAfter.
+ // Ignore the exception
}
}
};
@@ -475,8 +493,8 @@ public sealed partial class QuicStream
private unsafe int HandleEventReceive(ref RECEIVE data)
{
ulong totalCopied = (ulong)_receiveBuffers.CopyFrom(
- new ReadOnlySpan<QUIC_BUFFER>(data.Buffers, (int) data.BufferCount),
- (int) data.TotalBufferLength,
+ new ReadOnlySpan<QUIC_BUFFER>(data.Buffers, (int)data.BufferCount),
+ (int)data.TotalBufferLength,
data.Flags.HasFlag(QUIC_RECEIVE_FLAGS.FIN));
if (totalCopied < data.TotalBufferLength)
{