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

Comments

Projects
None yet
7 participants
@alexbrainman
Copy link
Member

commented Aug 30, 2013

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

This comment has been minimized.

Copy link
Member Author

commented Sep 19, 2013

Comment 1:

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 3:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 4:

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

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 5:

Labels changed: added repo-main.

@rsc rsc removed the os-windows label Apr 10, 2015

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc added OS-Windows and removed release-none labels Apr 10, 2015

@bradfitz

This comment has been minimized.

Copy link
Member

commented Apr 10, 2016

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

This comment has been minimized.

Copy link

commented Apr 10, 2016

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

This comment has been minimized.

Copy link
Contributor

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

If hostname part of an address is empty, assume localhost.
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>
@gopherbot

This comment has been minimized.

Copy link

commented Oct 25, 2016

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

@rsc

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

commented Oct 27, 2016

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

@gopherbot gopherbot closed this in 1a0b1cc Nov 2, 2016

mastercactapus added a commit to mastercactapus/caddy that referenced this issue Jan 13, 2017

fix proxy protocol tests in windows
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.
You can’t perform that action at this time.