Skip to content

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

Open

Description

@Ailloviee

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

Activity

  1. added
    api-suggestion
    on May 6, 2022
  2. ghost added
    untriaged
    on May 6, 2022
  3. ManickaP commented on May 6, 2022

    @ManickaP
    Member

    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.

  4. MihaZupan commented on May 6, 2022

    @MihaZupan
    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

  5. wfurt commented on May 6, 2022

    @wfurt
    Member

    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.

  6. added this to the Future milestone on May 10, 2022
  7. ghost removed
    untriaged
    on May 10, 2022
  8. karelz commented on May 10, 2022

    @karelz
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-System.Net.Http

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions