Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] Swallow ObjectDisposedException when aborting QuicStream from CancellationAction #75179

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Changes from all commits
Commits
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
30 changes: 24 additions & 6 deletions src/libraries/System.Net.Quic/src/System/Net/Quic/QuicStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
};
Expand All @@ -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
}
}
};
Expand Down Expand Up @@ -475,8 +493,8 @@ private unsafe int HandleEventStartComplete(ref START_COMPLETE data)
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)
{
Expand Down