- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
csharpier server and ipv6 #1242
Comments
I spent way too much time debating which option to go with, and decided to just go with updating the extensions because it would be easier to test. Probably could have had all 3 extensions updated in the time I debated it. Thanks for all the details! The vscode fix is out nowish and VS + Rider will be along shortly. |
belav
added a commit
that referenced
this issue
Apr 26, 2024
Thanks, 1.7.2 works |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Environments
Log Output
["WARN" - 9:34:00 AM] Failed posting to the csharpier server. FetchError: request to http://localhost:49152/format failed, reason: connect ECONNREFUSED ::1:49152
Steps to reproduce
Configure your system so that localhost resolve to the IPv6 address ::1 instead of 127.0.0.1
The Problem
So looking at the code which starts the server, https://github.com/belav/csharpier/blob/main/Src/CSharpier.Cli/Server/ServerFormatter.cs#L23 it is passing the
IPAddress.Loopback
field to kestrel, and from the docs https://learn.microsoft.com/en-us/dotnet/api/system.net.ipaddress.loopback theIPAdress.Loopback
is the IPv4 address 127.0.0.1Therefore, csharpier only binds to the IPv4 address 127.0.0.1. I can confirm that using lsof to list open ports, csharpier is listening only on 127.0.0.1:49152 and not listening on IPv6 ::1
The problem is the vscode extension is attempting to connect to http://localhost:49152 which resolves to the IPv6 address ::1 and thus gets a connection refused.
Two possible fixes
One option is to change the vscode extension to connect to http://127.0.0.1:49152 so that it always uses IPv4 to connect, using the explicit IPv4 address instead of relying on localhost
Or, the Kestrel documentation here https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-8.0#url-formats says the following:
So instead of passing
IPAddress.Loopback
, just pass the string "localhost". It seems there is IPAddress.IPv6Loopback field but I think just using the string "localhost" and letting kestrel do it is probably better.The text was updated successfully, but these errors were encountered: