File tree Expand file tree Collapse file tree 2 files changed +21
-41
lines changed
Expand file tree Collapse file tree 2 files changed +21
-41
lines changed Original file line number Diff line number Diff line change @@ -303,8 +303,23 @@ internal void OnContentWritingCompleted()
303303 {
304304 this . DisposeSelfOnFailure ( Task . Run ( async delegate
305305 {
306- var writer = await this . GetReceivedMessagePipeWriterAsync ( ) . ConfigureAwait ( false ) ;
307- writer . Complete ( ) ;
306+ if ( ! this . IsDisposed )
307+ {
308+ try
309+ {
310+ var writer = await this . GetReceivedMessagePipeWriterAsync ( ) . ConfigureAwait ( false ) ;
311+ writer . Complete ( ) ;
312+ }
313+ catch ( ObjectDisposedException )
314+ {
315+ this . mxStreamIOWriter ? . Complete ( ) ;
316+ }
317+ }
318+ else
319+ {
320+ this . mxStreamIOWriter ? . Complete ( ) ;
321+ }
322+
308323 this . mxStreamIOWriterCompleted . Set ( ) ;
309324 } ) ) ;
310325 }
Original file line number Diff line number Diff line change @@ -707,58 +707,23 @@ private async Task ReadStreamAsync()
707707 break ;
708708 }
709709 }
710-
711- await this . CompleteWritingOnAllChannelsAsync ( ) . ConfigureAwait ( false ) ;
712710 }
713711 catch ( EndOfStreamException )
714712 {
715713 // When we unexpectedly hit an end of stream, just close up shop.
716- await this . CompleteWritingOnAllChannelsAsync ( ) . ConfigureAwait ( false ) ;
717- }
718- catch ( OperationCanceledException )
719- {
720- // We don't need to propagate a cancellation exception either.
721- await this . CompleteWritingOnAllChannelsAsync ( ) . ConfigureAwait ( false ) ;
722714 }
723- catch ( Exception ex )
724- {
725- await this . CompleteWritingOnAllChannelsAsync ( ex ) . ConfigureAwait ( false ) ;
726- throw ;
727- }
728-
729- this . Dispose ( ) ;
730- }
731-
732- private async Task CompleteWritingOnAllChannelsAsync ( Exception ex = null )
733- {
734- ValueTask < PipeWriter > [ ] pipeWriters = null ;
735- try
715+ finally
736716 {
737- int writersCount ;
738717 lock ( this . syncObject )
739718 {
740- writersCount = this . openChannels . Count ;
741- pipeWriters = ArrayPool < ValueTask < PipeWriter > > . Shared . Rent ( writersCount ) ;
742- int i = 0 ;
743719 foreach ( var entry in this . openChannels )
744720 {
745- pipeWriters [ i ++ ] = entry . Value . GetReceivedMessagePipeWriterAsync ( ) ;
721+ entry . Value . OnContentWritingCompleted ( ) ;
746722 }
747723 }
748-
749- for ( int i = 0 ; i < writersCount ; i ++ )
750- {
751- var writer = await pipeWriters [ i ] . ConfigureAwait ( false ) ;
752- writer . Complete ( ex ) ;
753- }
754- }
755- finally
756- {
757- if ( pipeWriters != null )
758- {
759- ArrayPool < ValueTask < PipeWriter > > . Shared . Return ( pipeWriters ) ;
760- }
761724 }
725+
726+ this . Dispose ( ) ;
762727 }
763728
764729 /// <summary>
You can’t perform that action at this time.
0 commit comments