-
Notifications
You must be signed in to change notification settings - Fork 18k
net: The requested address is not valid in its context. #34171
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
Comments
This is not a Go issue, it is a Windows feature (google "strong host model"). The same thing happens with any other programming language. You can connect to "192.168.1.114:8080" in your example, but not 127.0.0.1 as you bound to another interface. What are you trying to achieve by binding the tcp client to a specific local address? |
There are multiple default routes to different gateways on my machine, something looks like this:
By default traffic are going out through 10.255.0.2, while some traffic are desired to go out through 192.168.1.114, via binding to that interface. But if it's the case that the destination address is 127.0.0.1, and we are binding to 192.168.1.114, the above error occurs. In fact, it's quite easy to distinguish traffic targeting 127.0.0.1 and don't bind to a specific interface while sending them, just would like to know if there is a cleaner solution. @antong I tried to disable the strong host model with the following commands, and the program still fails, am I missing something?
|
I also tried to send traffic to another interface (192.168.119.49), with the strong host model enabled for both interfaces (192.168.119.49 and 192.168.1.114), I got a different error:
With the strong host model disabled, it worked. But it failed anyway when sending to the loopback interface, it's seems that the loopback is somewhat special, and it's not related to the strong host model. |
Closing since it's indeed not a Go specific issue. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run the following code,
192.168.1.114
is the IP address of the local network adapter.What did you expect to see?
Successfully connects to the TCP server listening at ":8080".
What did you see instead?
panic: dial tcp 192.168.1.114:0->127.0.0.1:8080: connectex: The requested address is not valid in its context.
goroutine 1 [running]:
main.main()
C:/share/gotest/main.go:17 +0x2bf
exit status 2
I am not sure if this is the expected behavior on Windows, but the code works fine on macOS, if that's expected, perhaps we should have it documented.
The text was updated successfully, but these errors were encountered: