@@ -70,9 +70,18 @@ public sealed partial class QuicStream
70
70
{
71
71
CancellationAction = target =>
72
72
{
73
- if ( target is QuicStream stream )
73
+ try
74
74
{
75
- stream . Abort ( QuicAbortDirection . Read , stream . _defaultErrorCode ) ;
75
+ if ( target is QuicStream stream )
76
+ {
77
+ stream . Abort ( QuicAbortDirection . Read , stream . _defaultErrorCode ) ;
78
+ }
79
+ }
80
+ catch ( ObjectDisposedException )
81
+ {
82
+ // We collided with a Dispose in another thread. This can happen
83
+ // when using CancellationTokenSource.CancelAfter.
84
+ // Ignore the exception
76
85
}
77
86
}
78
87
} ;
@@ -83,9 +92,18 @@ public sealed partial class QuicStream
83
92
{
84
93
CancellationAction = target =>
85
94
{
86
- if ( target is QuicStream stream )
95
+ try
96
+ {
97
+ if ( target is QuicStream stream )
98
+ {
99
+ stream . Abort ( QuicAbortDirection . Write , stream . _defaultErrorCode ) ;
100
+ }
101
+ }
102
+ catch ( ObjectDisposedException )
87
103
{
88
- stream . Abort ( QuicAbortDirection . Write , stream . _defaultErrorCode ) ;
104
+ // We collided with a Dispose in another thread. This can happen
105
+ // when using CancellationTokenSource.CancelAfter.
106
+ // Ignore the exception
89
107
}
90
108
}
91
109
} ;
@@ -491,8 +509,8 @@ private unsafe int HandleEventStartComplete(ref START_COMPLETE data)
491
509
private unsafe int HandleEventReceive ( ref RECEIVE data )
492
510
{
493
511
ulong totalCopied = ( ulong ) _receiveBuffers . CopyFrom (
494
- new ReadOnlySpan < QUIC_BUFFER > ( data . Buffers , ( int ) data . BufferCount ) ,
495
- ( int ) data . TotalBufferLength ,
512
+ new ReadOnlySpan < QUIC_BUFFER > ( data . Buffers , ( int ) data . BufferCount ) ,
513
+ ( int ) data . TotalBufferLength ,
496
514
data . Flags . HasFlag ( QUIC_RECEIVE_FLAGS . FIN ) ) ;
497
515
if ( totalCopied < data . TotalBufferLength )
498
516
{
0 commit comments