Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/6.0] Respect the Keep-Alive response header on HTTP/1.0 #73245

Conversation

MihaZupan
Copy link
Member

@MihaZupan MihaZupan commented Aug 2, 2022

Backport of #73020 and #73585
Fixes #72958

Customer Impact

There is an inherent race in HTTP/1.x between the server closing an idle connection and the client trying to send a request at the same time (#60644). To mitigate this, the server may respond with a Keep-Alive: timeout=60 header that informs the client of how long it can reuse an idle connection for.
This change makes SocketsHttpHandler look for this header and use it to limit the idle timeout of a connection.

As a result, we avoid the race condition and fewer requests fail with a "Connection reset by peer" error.

Testing

Targeted test cases have been added and the patch was validated by an internal party in production.

Risk

There is a tradeoff between mitigating the race condition and how long we consider an idle connection usable for.

There is a risk that the user may see more connections being established if they make requests on an interval that falls within a 1-second offset of the server Keep-Alive timeout.
For example, if the server responds with a timeout of 5 seconds and the user has a script pinging the server every 4.5 seconds, every request would create a new connection instead of reusing the existing one.
Users facing such an issue can increase the interval at which they make requests or if possible increase the timeout on the server.

* Respect the Keep-Alive response header on HTTP/1.0

* Remove TimeoutOffset

* Update Trace message

* Update tests

* Adjust test timeouts
@MihaZupan MihaZupan added this to the 6.0.x milestone Aug 2, 2022
@MihaZupan MihaZupan requested a review from karelz August 2, 2022 16:54
@ghost
Copy link

ghost commented Aug 2, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Backport of #73020
Fixes #72958

Customer Impact

ToDo

Testing

ToDo

Risk

ToDo

Author: MihaZupan
Assignees: -
Labels:

area-System.Net.Http

Milestone: 6.0.x

@karelz
Copy link
Member

karelz commented Aug 11, 2022

This PR has been pre-approved for 6.0.9 by Tactics today, pending final agreement with @stephentoub.
Marking it as Approved and 6.0.9 with NO-MERGE (for the final agreement on Mon to finish).

@karelz karelz modified the milestones: 6.0.x, 6.0.9 Aug 11, 2022
@karelz karelz added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) Servicing-approved Approved for servicing release labels Aug 11, 2022
@karelz
Copy link
Member

karelz commented Aug 12, 2022

Update: We have reached consensus over email with @stephentoub and decided to take this change into 7.0 and 6.0.x servicing. Removing the NO-MERGE label.
@MihaZupan please update the PR to contain both 7.0 PRs linked in top post. Then switch from Draft and I will review it. Thanks!

@karelz karelz removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Aug 12, 2022
@MihaZupan MihaZupan marked this pull request as ready for review August 12, 2022 15:57
Copy link
Member

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

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

Tactics approved.
Correct milestone applied.
No CI failures.
No OOB package authoring needed (System.Net.Http.csproj does not have <IsPackable>).
Signed off by area owner.
Ready to merge! :shipit:

@carlossanlop carlossanlop merged commit deebaea into dotnet:release/6.0 Aug 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Http Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants