Skip to content

Commit

Permalink
[release/6.0-rc1] Don't cache CanReuse value (#35676)
Browse files Browse the repository at this point in the history
* Don't cache CanReuse value

* Comment on when to use CanReuse

Co-authored-by: Sebastien Ros <sebastienros@gmail.com>
  • Loading branch information
github-actions[bot] and sebastienros authored Aug 25, 2021
1 parent e2f39fd commit a5f72e7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void Initialize(Http2StreamContext context)
{
base.Initialize(context);

CanReuse = false;
_decrementCalled = false;
_completionState = StreamCompletionFlags.None;
InputRemaining = null;
Expand Down Expand Up @@ -107,7 +106,16 @@ public bool ReceivedEmptyRequestBody
}
}

public bool CanReuse { get; private set; }
// We only want to reuse a stream that was not aborted and has completely finished writing.
// This ensures Http2OutputProducer.ProcessDataWrites is in the correct state to be reused.

// CanReuse must be evaluated on the main frame-processing looping after the stream is removed
// from the connection's active streams collection. This is required because a RST_STREAM
// frame could arrive after the END_STREAM flag is received. Only once the stream is removed
// from the connection's active stream collection can no longer be reset, and is safe to
// evaluate for pooling.

public bool CanReuse => !_connectionAborted && HasResponseCompleted;

protected override void OnReset()
{
Expand Down Expand Up @@ -164,9 +172,6 @@ public void CompleteStream(bool errored)
// connection's flow-control window.
_inputFlowControl.Abort();

// We only want to reuse a stream that was not aborted and has completely finished writing.
// This ensures Http2OutputProducer.ProcessDataWrites is in the correct state to be reused.
CanReuse = !_connectionAborted && HasResponseCompleted;
}
finally
{
Expand Down

0 comments on commit a5f72e7

Please sign in to comment.