Skip to content

NetworkInformationException: Permission denied (.NET 8 + Docker +GCloud) #94794

Closed

Description

@christosk92

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

Activity

  1. martincostello commented on Nov 15, 2023

    @martincostello
    Member

    This issue looks like it needs to be transferred to dotnet/runtime.

  2. transferred this issue fromdotnet/aspnetcoreon Nov 15, 2023
  3. ghost added
    untriaged
    on Nov 15, 2023
  4. gfoidl commented on Nov 15, 2023

    @gfoidl
    Member

    the moment the container is spun up

    Can you share which image the container is based?
    Is it a non-root image?
    Can you try a container that runs as root?

  5. wfurt commented on Nov 15, 2023

    @wfurt
    Member

    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.CreateSocket will attempt to create Nertlink socket 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.

  6. ManickaP commented on Nov 16, 2023

    @ManickaP
    Member

    This is a general problem for Alt-Svc handling, the spec says you need to clear them on network change RFC 7838:

    By default, cached alternative services will be cleared when the
    client detects a network change. Alternative services that are
    intended to be longer lived (such as those that are not specific to
    the client access network) can carry the "persist" parameter with a
    value "1" as a hint that the service is potentially useful beyond a
    network configuration change.

    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.

  7. rzikm commented on Nov 16, 2023

    @rzikm
    Member

    As a workaround, setting DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT env var to false should work.

  8. ManickaP commented on Nov 16, 2023

    @ManickaP
    Member

    Or programmatically with AppContext switch: "System.Net.SocketsHttpHandler.Http3Support".

  9. self-assigned this
    on Nov 16, 2023
  10. ghost added
    in-pr
    on Nov 16, 2023
  11. 11 remaining items

  12. rzikm commented on Nov 29, 2023

    @rzikm
    Member

    What does it mean for networking/security (with February release)

    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).

  13. ghost added
    in-pr
    on Nov 29, 2023
  14. christosk92 commented on Nov 29, 2023

    @christosk92
    ContributorAuthor

    What does it mean for networking/security (with February release)

    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).

    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?

  15. rzikm commented on Nov 29, 2023

    @rzikm
    Member

    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?

    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.

  16. christosk92 commented on Nov 29, 2023

    @christosk92
    ContributorAuthor

    Makes sense, thanks for the clarification.

  17. ghost removed
    in-pr
    on Dec 6, 2023
  18. rzikm commented on Dec 6, 2023

    @rzikm
    Member

    Fix will be published in 8.0.2 release: #95123

  19. modified the milestones: 8.0.x, 8.0.2 on Dec 6, 2023
  20. nthonymiller commented on Dec 8, 2023

    @nthonymiller

    As a workaround, setting DOTNET_SYSTEM_NET_HTTP_SOCKETSHTTPHANDLER_HTTP3SUPPORT env var to false should work.

    Thanks for workaround, I ran into the exact same issue except I was using FirebaseAdmin package to validate an JWT.

      decodedToken = await firebaseAuth.VerifyIdTokenAsync(idToken);
    
  21. locked and limited conversation to collaborators on Jan 8, 2024
  22. modified the milestones: 8.0.2, 8.0.x on Jun 24, 2024
  23. karelz commented on Jun 24, 2024

    @karelz
    Member

    Fixed in main (9.0) in PR #94861 and in 8.0.2 in PR #95123.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions