Skip to content

Commit bcdb82d

Browse files
authored
Prevent Http2Stream pooling when reset frame is received (#35575)
1 parent 8ba6ea4 commit bcdb82d

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public void Initialize(Http2StreamContext context)
4141
{
4242
base.Initialize(context);
4343

44-
CanReuse = false;
4544
_decrementCalled = false;
4645
_completionState = StreamCompletionFlags.None;
4746
InputRemaining = null;
@@ -107,7 +106,16 @@ public bool ReceivedEmptyRequestBody
107106
}
108107
}
109108

110-
public bool CanReuse { get; private set; }
109+
// We only want to reuse a stream that was not aborted and has completely finished writing.
110+
// This ensures Http2OutputProducer.ProcessDataWrites is in the correct state to be reused.
111+
112+
// CanReuse must be evaluated on the main frame-processing looping after the stream is removed
113+
// from the connection's active streams collection. This is required because a RST_STREAM
114+
// frame could arrive after the END_STREAM flag is received. Only once the stream is removed
115+
// from the connection's active stream collection can no longer be reset, and is safe to
116+
// evaluate for pooling.
117+
118+
public bool CanReuse => !_connectionAborted && HasResponseCompleted;
111119

112120
protected override void OnReset()
113121
{
@@ -164,9 +172,6 @@ public void CompleteStream(bool errored)
164172
// connection's flow-control window.
165173
_inputFlowControl.Abort();
166174

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

0 commit comments

Comments
 (0)