Repository navigation
Closed
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Identical code (below) that works fine in .NET 7, fails with the following error in .NET 8:
Unhandled exception. System.Net.NetworkInformation.NetworkInformationException (13): Permission denied
2023-11-16 02:04:53.524 JST
at System.Net.NetworkInformation.NetworkChange.CreateSocket()
2023-11-16 02:04:53.524 JST
at System.Net.NetworkInformation.NetworkChange.add_NetworkAddressChanged(NetworkAddressChangedEventHandler value)
2023-11-16 02:04:53.524 JST
at System.Net.Http.HttpConnectionPoolManager.StartMonitoringNetworkChanges()
2023-11-16 02:04:53.524 JST
at System.Net.Http.HttpConnectionPool.HandleAltSvc(IEnumerable`1 altSvcHeaderValues, Nullable`1 responseAge)
2023-11-16 02:04:53.524 JST
at System.Net.Http.HttpConnectionPool.ProcessAltSvc(HttpResponseMessage response)
2023-11-16 02:04:53.524 JST
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
2023-11-16 02:04:53.524 JST
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
2023-11-16 02:04:53.524 JST
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
Trimmed and adjusted code (same result for ANY https call):
var httpClient = new HttpClient();
_ = await httpClient.GetAsync("https://www.google.com");The peculiarity of this issue lies in the fact that the code executes fine on a local environment. But the moment the container is spun up in a google cloud run instance, it fails.
Another weird thing is that raw TCP connections work fine, we have a database connection that goes directly over TCP, rather than traditional HTTP(s).
I have spent hours debugging this issue, and sadly we have no other choice but to revert back to .NET 7 for the time being.
Expected Behavior
A Proper HTTPs connection
Steps To Reproduce
No response
Exceptions (if any)
NetworkInformationException
.NET Version
.NET 8
Anything else?
No response
Reacted by Stig Rune, Adam Williams, moander, okcodes and Carlos
Activity
martincostello commentedon Nov 15, 2023
This issue looks like it needs to be transferred to dotnet/runtime.
gfoidl commentedon Nov 15, 2023
Can you share which image the container is based?
Is it a non-root image?
Can you try a container that runs as root?
wfurt commentedon Nov 15, 2023
That seems to come from HTTP/3 processing. What do you use as request version @christosk92?
I think the default is enabled in in .NET 8 but there should be ways how to suppress that.
https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-http3
Now, if my theory is right, you should see same behavior with .NET 7 if you enable HTTP/3.
The
NetworkChange.CreateSocketwill attempt to createNertlinksocket and it seems like that is not permitted in your container. (you can create simple app to verify that)Perhaps something HttpClient can handle better. I feel we should not fail if there is path forward with HTTP/1.1 or H/2.
ManickaP commentedon Nov 16, 2023
This is a general problem for Alt-Svc handling, the spec says you need to clear them on network change RFC 7838:
We just happen to use Alt-Svc only for H/3. So disabling it is a workaround.
I agree with Tomas, we should fix this, at least catch the exception and continue business as usual. If we're not able to detect network changes due to access rights limitations we won't.
rzikm commentedon Nov 16, 2023
As a workaround, setting
DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORTenv var tofalseshould work.ManickaP commentedon Nov 16, 2023
Or programmatically with
AppContextswitch: "System.Net.SocketsHttpHandler.Http3Support".11 remaining items
rzikm commentedon Nov 29, 2023
option 1. RFC does not require clients to do network monitoring. So in case we cannot detect network changes (due to constrained environment), the alt-svc headers will still get invalidated by the timeout specified in the header.
Note also that for HTTP/3 to work, you need to install MsQuic on the machine (on Linux, on windows the dll is distributed with the runtime).
christosk92 commentedon Nov 29, 2023
So this means dockerfiles should be adjusted accordingly to install MsQuic? Or are they already included if youre using the msft docker images to build your .net container?
rzikm commentedon Nov 29, 2023
Yes, published docker images do not install msquic and it needs to be installed separately. MsQuic does not publish official packages for all distributions supported by .NET and thus installing it nowhere by default is better than installing it only on some. Also, not all applications make use of QUIC or HTTP/3 so it makes sense for user to specifically opt in for this feature.
christosk92 commentedon Nov 29, 2023
Makes sense, thanks for the clarification.
rzikm commentedon Dec 6, 2023
Fix will be published in 8.0.2 release: #95123
nthonymiller commentedon Dec 8, 2023
Thanks for workaround, I ran into the exact same issue except I was using FirebaseAdmin package to validate an JWT.
karelz commentedon Jun 24, 2024
Fixed in main (9.0) in PR #94861 and in 8.0.2 in PR #95123.