Skip to content

HttpClient.GetAsync(...) throws Win32Exception when request sent first to https://FQDN and then to https://FQDN:8000 #98691

Open
@davidkaya

Description

Description

Hello,

we have encountered a weird behaviour where if we create a HttpClient and first send a request (e.g. using HttpClient.GetAsync) to https://<redacted>.com and then to https://<redacted>.com:8000, we get a System.ComponentModel.Win32Exception (0x80090304): The Local Security Authority cannot be contacted. But if we do it the other way around, i.e. sending the request first to :8000 and then to uri without port (i.e. :443), it works just fine.

Is this an expected behaviour?

Reproduction Steps

// The FQDN is the same in all cases

// Does not work (throws exception)
/*
 * Unhandled exception. System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> System.ComponentModel.Win32Exception (0x80090304): The Local Security Authority cannot be contacted
   --- End of inner exception stack trace ---
   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](Boolean receiveFirst, Byte[] reAuthenticationData, CancellationToken cancellationToken)
   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptions sslOptions, HttpRequestMessage request, Boolean async, Stream stream, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Program.<Main>$(String[] args) in C:\workspace\work\temp\ConsoleApp3\ConsoleApp3\Program.cs:line 5
 */
var firstHttpClient = new HttpClient();
await firstHttpClient.GetAsync("https://<redacted>.com");
await firstHttpClient.GetAsync("https://<redacted>.com:8000"); // <- this call throws the exception above

// Works (no exception)
var secondHttpClient = new HttpClient();
await secondHttpClient.GetAsync("https://<redacted>.com:8000");
await secondHttpClient.GetAsync("https://<redacted>.com");

Expected behavior

No exception is thrown and it doesn't depend in which order we send requests.

Actual behavior

An exception is thrown (see reproduction steps).

Regression?

No response

Known Workarounds

The workaround for us is to use separate HttpClient instances.

Configuration

net8 running on x64 Windows 11.

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions