Skip to content
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

net: connecting to 0.0.0.0 fails on windows #6290

Closed
alexbrainman opened this issue Aug 30, 2013 · 11 comments
Closed

net: connecting to 0.0.0.0 fails on windows #6290

alexbrainman opened this issue Aug 30, 2013 · 11 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@alexbrainman
Copy link
Member

What steps will reproduce the problem?

run this program on windows

package main

import (
    "log"
    "net"
)

func dial() error {
    l, err := net.Listen("tcp", ":0")
    if err != nil {
        return err
    }

    go func() {
        c, err := l.Accept()
        if err != nil {
            return
        }
        c.Close()
    }()

    c, err := net.Dial("tcp", l.Addr().String())
    if err != nil {
        return err
    }
    c.Close()
    return nil
}

func main() {
    err := dial()
    if err != nil {
        log.Fatal(err)
    }
}


What is the expected output?

Should output noting.

What do you see instead?

2013/08/30 16:43:22 dial tcp 0.0.0.0:1406: ConnectEx tcp: The format of the specified
network name is invalid.

Please use labels and text to provide additional information.

The problem seems to be that l.Addr().String() returns '0.0.0.0', but connecting to that
address is not allowed on windows. From
http://msdn.microsoft.com/en-us/library/aa923167.aspx

" ... If the address member of the structure specified by the name parameter is
all zeroes, connect will return the error WSAEADDRNOTAVAIL. ..."
@alexbrainman
Copy link
Member Author

Comment 1:

mikio,
Can we, please, decide what to do here? Thank you.
Alex

@mikioh
Copy link
Contributor

mikioh commented Sep 19, 2013

Comment 2:

I think accepting an wildcard address "0.0.0.0" or "::" might be better but let's
postpone until Go 1.3 because I'm not sure what happens in the case of raw socket on
Windows.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 3:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 5:

Labels changed: added repo-main.

@bradfitz
Copy link
Contributor

Let's at least remove that example from the docs on the Dial func. It's weird to connect to 0.0.0.0.

@taylorchu
Copy link

The doc says: If the host is empty, as in ":80", the local system is assumed. I interpret that local system as localhost (127.0.0.1) instead of 0.0.0.0. It will be nice if this is clarified in the doc.

@bradfitz bradfitz modified the milestones: Go1.7, Unplanned Apr 10, 2016
@mikioh
Copy link
Contributor

mikioh commented Apr 11, 2016

#10624 will update the documentation; It will probably have a section about "Network and host/address arguments."

@rsc rsc modified the milestones: Go1.8, Go1.7 May 18, 2016
anusha-ragunathan added a commit to anusha-ragunathan/go-plugins-helpers that referenced this issue Sep 19, 2016
Binding plugins to a TCP port on localhost using ServeTCP("foo", ":12345")
does not work on Windows. This is because the golang net package does
not handle empty hostname/IP. golang/go#6290
tracks it and is slated to be fixed in Go 1.8.

This change explicitly adds "localhost" if there's no hostname and
serve as a workaround until Golang fixes it.

Signed-off-by: Anusha Ragunathan <anusha@docker.com>
@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 7, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31950 mentions this issue.

@rsc
Copy link
Contributor

rsc commented Oct 27, 2016

I think we should fix this. We advertise that Dial(":80") connects to the local system's port 80. It should do that on Windows too. I'll send a CL with a test and a fix; criticisms welcome.

@gopherbot
Copy link

CL https://golang.org/cl/32101 mentions this issue.

mastercactapus added a commit to mastercactapus/caddy that referenced this issue Jan 13, 2017
updated proxy protocol tests to work in windows with golang < 1.8

for reference: the inconsistency was documented in golang/go#6290 and was fixed with golang/go@1a0b1cc
@golang golang locked and limited conversation to collaborators Nov 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

7 participants