dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.38k stars 4.75k forks source link

[Weird] HTTP/3 does not work after publishing app, but works on debug and release #79727

Closed alexandrehtrb closed 1 year ago

alexandrehtrb commented 1 year ago

Description

Hello,

I have a weird bug, that my app can make HTTP/3 requests when running on debug or release, but, when the app is published, it cannot make such requests. My app is an Avalonia desktop app in .NET 6. This bug happens in both Linux and Windows versions of the app.

Reproduction Steps

1) Make a .NET 6 app with a HttpClient making HTTP/3 requests

2) The app's .csproj has:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <DebugType>embedded</DebugType>
    <EnablePreviewFeatures>True</EnablePreviewFeatures>
    <EnableCompressionInSingleFile>True</EnableCompressionInSingleFile>
    <PublishReadyToRun>True</PublishReadyToRun>
  </PropertyGroup>
<ItemGroup>
  <RuntimeHostConfigurationOption Include="System.Net.SocketsHttpHandler.Http3Support" Value="true" />
</ItemGroup>

3) Publish this app like below:

dotnet publish ./src/Pororoca.Desktop/Pororoca.Desktop.csproj `
        --verbosity quiet `
        --nologo `
        --configuration Release `
        -p:PublishSingleFile=true `
        --self-contained true `
        --runtime "win-x64" `
        --output "./out/win-x64/"

Expected behavior

Should make HTTP/3 requests without problems, because it works with dotnet run, whether it is on Debug or Release configurations

Actual behavior

The following Exception is thrown:

System.Net.Http.HttpRequestException: Requesting HTTP version 3.0 with version policy RequestVersionExact while unable to establish HTTP/3 connection.
   at System.Net.Http.HttpConnectionPool.ThrowGetVersionException(HttpRequestMessage request, Int32 desiredVersion)
   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.DecompressionHandler.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 Pororoca.Infrastructure.Features.Requester.PororocaRequester.RequestAsync(IPororocaVariableResolver variableResolver, PororocaHttpRequest req, Boolean disableSslVerification, CancellationToken cancellationToken) in C:\Projetos\Pororoca\src\Pororoca.Infrastructure\Features\Requester\PororocaRequester.cs:line 37

Regression?

No response

Known Workarounds

No response

Configuration

Running on .NET 6, last app version was compiled with 6.0.403; Bug confirmed on Linux x64 and Windows 11 x64

Other information

The URLs that I use for testing HTTP/3 are:

https://cloudflare-quic.com/

https://quic.aiortc.org/

The error happens with both of them...

My project is on GitHub, if you want to use it to reproduce the bug:

https://github.com/alexandrehtrb/Pororoca

ghost commented 1 year ago

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details
### Description Hello, I have a weird bug, that my app can make HTTP/3 requests when running on debug or release, but, when the app is published, it cannot make such requests. My app is an Avalonia desktop app in .NET 6. This bug happens in both Linux and Windows versions of the app. ### Reproduction Steps 1) Make a .NET 6 app with a HttpClient making HTTP/3 requests 2) The app's .csproj has: ```xml net6.0 enable enable embedded True True True ``` 3) Publish this app like below: ```ps1 dotnet publish ./src/Pororoca.Desktop/Pororoca.Desktop.csproj ` --verbosity quiet ` --nologo ` --configuration Release ` -p:PublishSingleFile=true ` --self-contained true ` --runtime "win-x64" ` --output "./out/win-x64/" ``` ### Expected behavior Should make HTTP/3 requests without problems, because it works with `dotnet run`, whether it is on Debug or Release configurations ### Actual behavior The following Exception is thrown: ``` System.Net.Http.HttpRequestException: Requesting HTTP version 3.0 with version policy RequestVersionExact while unable to establish HTTP/3 connection. at System.Net.Http.HttpConnectionPool.ThrowGetVersionException(HttpRequestMessage request, Int32 desiredVersion) 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.DecompressionHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Pororoca.Infrastructure.Features.Requester.PororocaRequester.RequestAsync(IPororocaVariableResolver variableResolver, PororocaHttpRequest req, Boolean disableSslVerification, CancellationToken cancellationToken) in C:\Projetos\Pororoca\src\Pororoca.Infrastructure\Features\Requester\PororocaRequester.cs:line 37 ``` ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration Running on .NET 6, last app version was compiled with 6.0.403; Bug confirmed on Linux x64 and Windows 11 x64 ### Other information The URLs that I use for testing HTTP/3 are: https://cloudflare-quic.com/ https://quic.aiortc.org/ The error happens with both of them... My project is on GitHub, if you want to use it to reproduce the bug: https://github.com/alexandrehtrb/Pororoca
Author: alexandrehtrb
Assignees: -
Labels: `area-System.Net.Http`
Milestone: -
vitek-karas commented 1 year ago

This is very likely same issue as https://github.com/dotnet/runtime/issues/73290 On Windows the workaround is to copy the msquic.dll file from the runtime install next to your application. On Linux the msquic needs to be installed - @ManickaP @wfurt for more info.

rzikm commented 1 year ago

Closing as duplicate of #73290