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

[API Proposal]: Enable DNS Round Robin as a configurable option for SocketsHttpHandler #68967

Open
Ailloviee opened this issue May 6, 2022 · 5 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net.Http
Milestone

Comments

@Ailloviee
Copy link

Background and motivation

A lot of our services previously use System.Net.ServicePointManager to manage connections to URIs in .Net Framework, and there was an option ServicePointManager.EnableDnsRoundRobin that we could enable to load balance requests with round robin DNS resolution. However, as we are migrating these services to .Net Core where ServicePointManager becomes legacy and System.Net.Http.SocketsHttpHandler is used for managing connections instead, the built-in DNS resolution logic does not support round robin. Per connection, it tries the host's list of IP addresses starting from index 0, directing all requests to that address until connection fails or until cache is refreshed. I propose that we add EnableDnsRoundRobin as a public field in SocketsHttpHandler so that, when it's set to true, the DNS resolution part of the connection will be handled using round robin similarly to how it's done in ServicePointManager.

API Proposal

namespace System.Net.Http
{
    public sealed class SocketsHttpHandler : HttpMessageHandler
    {
        public bool EnableDnsRoundRobin;
}

API Usage

var handler = new SocketsHttpHandler();
handler.EnableDnsRoundRobin = true;

Alternative Designs

No response

Risks

No response

@Ailloviee Ailloviee added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label May 6, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label May 6, 2022
@ghost
Copy link

ghost commented May 6, 2022

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

Issue Details

Background and motivation

A lot of our services previously use System.Net.ServicePointManager to manage connections to URIs in .Net Framework, and there was an option ServicePointManager.EnableDnsRoundRobin that we could enable to load balance requests with round robin DNS resolution. However, as we are migrating these services to .Net Core where ServicePointManager becomes legacy and System.Net.Http.SocketsHttpHandler is used for managing connections instead, the built-in DNS resolution logic does not support round robin. Per connection, it tries the host's list of IP addresses starting from index 0, directing all requests to that address until connection fails or until cache is refreshed. I propose that we add EnableDnsRoundRobin as a public field in SocketsHttpHandler so that, when it's set to true, the DNS resolution part of the connection will be handled using round robin similarly to how it's done in ServicePointManager.

API Proposal

namespace System.Net.Http
{
    public sealed class SocketsHttpHandler : HttpMessageHandler
    {
        public bool EnableDnsRoundRobin;
}

API Usage

var handler = new SocketsHttpHandler();
handler.EnableDnsRoundRobin = true;

Alternative Designs

No response

Risks

No response

Author: Ailloviee
Assignees: -
Labels:

api-suggestion, area-System.Net.Http, untriaged

Milestone: -

@ManickaP
Copy link
Member

ManickaP commented May 6, 2022

You can use ConnectCallback for this. It's more involved than a single boolean, but it can unblock you right now.

Also we have a more work planned around connection pooling and DNS, e.g.: happy eyeballs #26177. So we might consider this issue more as a request for a feature than a fully fledged API suggestion.

@MihaZupan
Copy link
Member

FWIW if anyone's blocked by the lack of this API, I put a (not really tested) implementation here: https://github.com/MihaZupan/DnsRoundRobin

@wfurt
Copy link
Member

wfurt commented May 6, 2022

If anything, I would much rather see connect policy instead of just bool. That would give user more control beyond just one type of preference. Perhaps what ever comes from #63162.

@karelz karelz added this to the Future milestone May 10, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label May 10, 2022
@karelz
Copy link
Member

karelz commented May 10, 2022

Triage: It might be useful together with other connection policies (Happy Eyeball).
There is a workaround, so not critical for 7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Net.Http
Projects
None yet
Development

No branches or pull requests

5 participants