runtime: Getting "The SSL connection could not be established" error when connecting to a certain website
Description
Using HttpClient, When attempting to make GET requests to a certain web address, the method occasionally fails with an error The SSL connection could not be established, see inner exception.
where the inner exception says Exception of type 'System.Net.InternalException' was thrown. -2146892963
. Occasionally is the key here - it sometimes “just works” (in the provided code below it should result in 503 Service Temporarily Unavailable when it works.)
Minimal reproducible code:
HttpClient client = new HttpClient();
await client.GetStringAsync("https://newbiepr.gitlab.io"); // Fails on this line
Exception details:
<div class="spacer">HttpRequestException<span class="fixedextenser">4</span> | ||||||||||||||||||||
The SSL connection could not be established, see inner exception. | ||||||||||||||||||||
Data |
| |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HelpLink | null | |||||||||||||||||||
HResult | -2146233088 | |||||||||||||||||||
InnerException |
| |||||||||||||||||||
Message | The SSL connection could not be established, see inner exception. | |||||||||||||||||||
Source | System.Net.Http | |||||||||||||||||||
StackTrace | at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Boolean async, Stream stream, SslClientAuthenticationOptions sslOptions, 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.GetHttpConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(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.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken) at System.Net.Http.HttpClient.GetStringAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken) at UserQuery.Main(), line 2 | |||||||||||||||||||
StatusCode | null |
Configuration
Windows version: Windows 10 Pro Insiders Preview Build 21364 (Dev ring), x64, Korean .NET SDK used: 5.0.200-preview.21077.7
Regression?
As far as I can tell it can be reproduced on .NET Framework 4.8 that’s installed on my Windows as well, albeit with a different error message:
HttpRequestException<span class="fixedextenser">4</span> | ||||||||||||||||||||||||
An error occurred while sending the request. | ||||||||||||||||||||||||
Data |
| |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
HelpLink | null | |||||||||||||||||||||||
HResult | -2146233088 | |||||||||||||||||||||||
InnerException |
| |||||||||||||||||||||||
Message | An error occurred while sending the request. | |||||||||||||||||||||||
Source | mscorlib | |||||||||||||||||||||||
StackTrace | 위치: System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 위치: System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 위치: System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 위치: UserQuery.<RunUserAuthoredQuery>d__0.MoveNext() 파일 C:\Users\gotos\AppData\Local\Temp\LINQPad5\_tjauvduk\query_uwxuos.cs:줄 41 |
Other information
As far as I can tell, I do not see any sort of similar errors showing up when I make the request with other tools such as curl
or Edge browser.
Might be related: https://github.com/dotnet/runtime/issues/44058 (although the issue was closed for insufficient info)
If you’re having trouble reproducing the issue I am happy to provide packet captures for troubleshooting.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 28 (28 by maintainers)
We had offline exchange with @Gnbrkm41 and TTD traces were collected. The issue is interop with zero length ticket_nonce when Schannel tries to resume previous session. The fix will be done in windows code and it should come from Windows update. In mean time, disabling TLS 1.3 is probably best workaround - either via registry or explicitly via ssl options.
thanks for confirmation @Gnbrkm41