File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -425,7 +425,7 @@ private enum ParsingState : byte
425425 Done
426426 }
427427
428- public override bool NeedsDrain => ( _connection != null ) ;
428+ public override bool NeedsDrain => CanReadFromConnection ;
429429
430430 public override async ValueTask < bool > DrainAsync ( int maxDrainBytes )
431431 {
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ private ReadOnlyMemory<byte> ReadFromConnectionBuffer(int maxBytesToRead)
190190 return connectionBuffer . Slice ( 0 , bytesToConsume ) ;
191191 }
192192
193- public override bool NeedsDrain => ( _connection != null ) ;
193+ public override bool NeedsDrain => CanReadFromConnection ;
194194
195195 public override async ValueTask < bool > DrainAsync ( int maxDrainBytes )
196196 {
Original file line number Diff line number Diff line change @@ -28,6 +28,17 @@ public HttpContentReadStream(HttpConnection connection) : base(connection)
2828
2929 protected bool IsDisposed => _disposed == 1 ;
3030
31+ protected bool CanReadFromConnection
32+ {
33+ get
34+ {
35+ // _connection == null typically means that we have finished reading the response.
36+ // Cancellation may lead to a state where a disposed _connection is not null.
37+ HttpConnection ? connection = _connection ;
38+ return connection != null && connection . _disposed != Status_Disposed ;
39+ }
40+ }
41+
3142 public virtual ValueTask < bool > DrainAsync ( int maxDrainBytes )
3243 {
3344 Debug . Fail ( $ "DrainAsync should not be called for this response stream: { GetType ( ) } ") ;
You can’t perform that action at this time.
0 commit comments