microsoft-authentication-library-for-dotnet icon indicating copy to clipboard operation
microsoft-authentication-library-for-dotnet copied to clipboard

[Feature Request] Better default HTTPClient on .NET Core

Open bgavrilMS opened this issue 4 years ago • 2 comments
trafficstars

MSAL's default HttpClient does not handle DNS changes.

Proposal: use System.Net.Http.SocketsHttpHandler on confidential client flows

The configuration should be similar to

#if NETCOREAPP2_1_OR_GREATER
            // Starting with netcore2.1 and .NET5+, HttpClient maintains long lived socket connections and as a result does
            // not respect DNS.  This enforces a reconnect and as a result a DNS update.
            var handler = new SocketsHttpHandler { PooledConnectionLifetime = TimeSpan.FromMinutes(15) };
            HttpClient = new HttpClient(handler) { Timeout = timeout, MaxResponseContentBufferSize = maxResponseDataSize };
#else
            HttpClient = new HttpClient() { Timeout = timeout, MaxResponseContentBufferSize = maxResponseDataSize };
#endif

bgavrilMS avatar Sep 07 '21 08:09 bgavrilMS

@pmaytak - based on error telemetry, is this worth doing?

bgavrilMS avatar Dec 21 '22 10:12 bgavrilMS

Based on the error telemetry - no, low ROI because errors are only a tiny amount of total requests. They do say there's perf improvement, so I would do it for general perf improvements. Maybe a P3?

pmaytak avatar Dec 22 '22 00:12 pmaytak