File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
System.Net.Http/src/System/Net/Http/SocketsHttpHandler Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ public void Dispose()
59
59
byte [ ] array = _bytes ;
60
60
_bytes = null ! ;
61
61
62
- if ( array != null )
62
+ if ( array is not null )
63
63
{
64
64
ReturnBufferIfPooled ( array ) ;
65
65
}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ internal sealed partial class Http2Connection : HttpConnectionBase
29
29
private readonly Stream _stream ;
30
30
31
31
// NOTE: These are mutable structs; do not make these readonly.
32
+ // ProcessIncomingFramesAsync and ProcessOutgoingFramesAsync are responsible for disposing/returning their respective buffers.
32
33
private ArrayBuffer _incomingBuffer ;
33
34
private ArrayBuffer _outgoingBuffer ;
34
35
@@ -245,6 +246,9 @@ public async ValueTask SetupAsync(CancellationToken cancellationToken)
245
246
}
246
247
catch ( Exception e )
247
248
{
249
+ // ProcessIncomingFramesAsync and ProcessOutgoingFramesAsync are responsible for disposing/returning their respective buffers.
250
+ // SetupAsync is the exception as it's responsible for starting the ProcessOutgoingFramesAsync loop.
251
+ // As we're about to throw and ProcessOutgoingFramesAsync will never be called, we must return the buffer here.
248
252
_outgoingBuffer . Dispose ( ) ;
249
253
250
254
Dispose ( ) ;
@@ -1886,6 +1890,10 @@ private void FinalTeardown()
1886
1890
_connectionWindow . Dispose ( ) ;
1887
1891
_writeChannel . Writer . Complete ( ) ;
1888
1892
1893
+ // We're not disposing the _incomingBuffer and _outgoingBuffer here as they may still be in use by
1894
+ // ProcessIncomingFramesAsync and ProcessOutgoingFramesAsync respectively, and those methods are
1895
+ // responsible for returning the buffers.
1896
+
1889
1897
if ( HttpTelemetry . Log . IsEnabled ( ) )
1890
1898
{
1891
1899
if ( Interlocked . Exchange ( ref _markedByTelemetryStatus , TelemetryStatus_Closed ) == TelemetryStatus_Opened )
You can’t perform that action at this time.
0 commit comments