dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.22k stars 4.72k forks source link

Happy Eyeballs support in Socket.ConnectAsync #861

Closed scalablecory closed 4 years ago

scalablecory commented 5 years ago

This proposal adds APIs needed to implement RFC 8305 "Happy Eyeballs" in Socket.ConnectAsync. This depends on #939.

The simplified description of Happy Eyeballs is that it makes A and AAAA DNS requests in parallel, and then goes back and forth between A and AAAA beginning parallel Connect() at a set interval until it has a connection. This trades more overhead for improved latency of the root ConnectAsync call.

See https://github.com/dotnet/runtime/issues/26177#issuecomment-540141586 where we decided to explore this as a general Socket feature rather than only SocketsHttpClient.

(API has cancellation support added where there previously hasn't been, to avoid needing to add yet more APIs later. See related #921)

class System.Net.Sockets.Socket
{
    public static bool ConnectAsync (SocketType socketType, ProtocolType protocolType, SocketAsyncEventArgs e, ConnectAlgorithm connectAlgorithm);
}

enum System.Net.Sockets.ConnectAlgorithm
{
    // use existing behavior.
    Default,

    // use a Happy Eyeballs-like algorithm to connect.
    Parallel = 1
}

26177 would be implemented using this, but is not blocked by it.

scalablecory commented 5 years ago

Triage: split dns changes into separate issue, track optimizing existing Connect calls for AF-specific lookups.

karelz commented 4 years ago

Triage: Asked for too many times, we should try to address it in 5.0.

GrabYourPitchforks commented 4 years ago

Feedback:

scalablecory commented 4 years ago

Closing for mega-issue #33418.

paulomorgado commented 4 years ago

@GrabYourPitchforks,

From https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/enum:

✔️ DO name flag enums with plural nouns or noun phrases and simple enums with singular nouns or noun phrases.

So, adding or removing the [Flags] attribute has implications on the enum name.