dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.

Home Page:https://asp.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SignalR Client connection is very slow when adding kestrel section to appsettings.json file and setting https or http url.

Kyeong-min opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Added a Kestrel section to the appsettings.json file and added an Endpoints/Https/Url configuration to allow dynamic configuration of the https listening port outside of the program.

When the client creates a HubConnection and calls await StartAsync(), there is a delay of about 5 seconds until OnConnectedAsync is called on the hub.

If you set the same configuration in the Web API project and try to connect with a web browser, you can connect quickly without any delay, so we decided that this is a SignalR problem.

Am I missing something? Or is the document incorrect?

Expected Behavior

Even if you configure the Kestrel section according to the instructions in the docs given above, the client should connect very quickly.

Steps To Reproduce

I uploaded the project in which the problem occurs to github.
Check out the repositories below.

  • This is a .NET 5 project and was created in the VS2019 Community.
  • Even if I create a .NET 6 project in VS2022 Community with the same configuration, the same problem occurs.

https://github.com/Kyeong-min/SignalR_Test

Exceptions (if any)

No response

.NET Version

6.0.301

Anything else?

dotnet --info.txt

  • The SignalR hub program runs as Kestrel's own host.
  • This issue occurred in both .NET 5 and .NET 6.
  • I had the same problem on different development machines (Windows 10, Windows 11).
  • If you delete the Kestrel section from your appsettings.json file, the client connects to the hub very quickly with no problems.
  • When I connect to the SignalR hub endpoint as a website, it responds very quickly with the string "Connection ID required" with a 400 status code.
  • Using the snippet code below, the client connects quickly. But I think this shouldn't be radically different from adding a kestrel section to your appsettings.json file.
    webBuilder.UseUrls("https://*:5101");

The address you put in your appsettings is https://0.0.0.0:5101. 0.0.0.0 means to bind to all IPv4 addresses. The * in https://*:5101 means to bind to all IPv4 and IPv6 addresses. The 5s pause is the client trying to connect to ::1, the IPv6 loopback address, timing out, and then falling back to 127.0.0.1.

Fix: Put https://*:5101 in appsettings.json.

Thank you for your interest in this issue.

Obviously, this is my mistake.
When connecting to localhost, I did not think that ::/0 would try to connect first.