Skip to content

Don't cache CanReuse value - #35575

Merged
sebastienros merged 2 commits into
mainfrom
sebros/http2streamreuse
Aug 24, 2021
Merged

sebastienros merged 2 commits into
mainfrom
sebros/http2streamreuse

Conversation

@sebastienros

@sebastienros sebastienros commented Aug 20, 2021 •

Copy link
Copy Markdown
Member

Fixes #34768

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Worst case is that Http2 streams are pooled less often.

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

// This ensures Http2OutputProducer.ProcessDataWrites is in the correct state to be reused.
public bool CanReuse => !_connectionAborted && HasResponseCompleted;

protected override void OnReset()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would resetting the value to false in OnReset accomplish the same goal?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line on 44 was effectively doing that before. The issue was that !_connectionAborted && HasResponseCompleted was being evaluated too early on a background thread and a RST_STREAM frame could still be processed and abort the stream before pooling. Now CanReuse is evaluated once in the main frame-processing loop right before it's pooled or not.

@JamesNK JamesNK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit test. This is subtle behavior and we want to ensure it isn't regressed in the future.

Where is _connectionAborted set to true? Will it always happen before the stream is pooled? I want to make sure there is no chance that a stream is pooled and then some code aborts it while it is in the pool.

@sebastienros

sebastienros commented Aug 20, 2021 •

Copy link
Copy Markdown
Member Author

@halter73

Copy link
Copy Markdown
Member

Please add a unit test.

I would also love that if you find a good way to do it @JamesNK. The problem is the RST_STREAM frame needs to be processed between Http2Stream.CompleteStream(bool) executing on a background thread and Http2Connection.UpdateCompletedStreams() running again.

This would be easy enough to do by adding some sort of event/resettable-Task we could hook in the tests when Http2Connection.OnStreamCompleted() is called and only setting the RST_STREAM frame then, but the problem there is that UpdateCompletedStreams() runs immediately after await Input.ReadAsync() completes without processing any incoming frames. So we'd also need a way to force processing frames without calling UpdateCompletedStreams() to simulate Http2Connection frame-processing loop running concurrently with Http2Stream.CompleteStream(bool). I'm not sure it's worth it.

@JamesNK

JamesNK commented Aug 21, 2021 •

Copy link
Copy Markdown
Member

Ok. If we can't add a unit test then we should comment. Something like:

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.

@davidfowl

Copy link
Copy Markdown
Member

Nice catch!

@davidfowl

Copy link
Copy Markdown
Member

Why is this is main and not rc1?

@sebastienros
sebastienros requested a review from JamesNK August 24, 2021 21:28
@sebastienros
sebastienros enabled auto-merge (squash) August 24, 2021 21:30
@sebastienros
sebastienros disabled auto-merge August 24, 2021 21:33
@sebastienros

Copy link
Copy Markdown
Member Author

@davidfowl merge to main, then backport to rc1 (standard procedure I believe)

@sebastienros
sebastienros enabled auto-merge (squash) August 24, 2021 22:06
@sebastienros

Copy link
Copy Markdown
Member Author

/backport to release/6.0-rc1

@github-actions

Copy link
Copy Markdown
Contributor

@sebastienros
sebastienros merged commit bcdb82d into main Aug 24, 2021
@sebastienros
sebastienros deleted the sebros/http2streamreuse branch August 24, 2021 23:03
@ghost ghost added this to the 7.0-preview1 milestone Aug 24, 2021
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kestrel reset error when no reset received

6 participants