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: net.Listen("tcp", "") also listens on IPv6 #17615

mikioh opened this issue Oct 26, 2016 · 4 comments

net: net.Listen("tcp", "") also listens on IPv6 #17615

mikioh opened this issue Oct 26, 2016 · 4 comments


Copy link

@mikioh mikioh commented Oct 26, 2016

I was asked several times on golang-nuts, golang-dev or golang-codereviews like the following:

Copy link

@bradfitz bradfitz commented Oct 26, 2016

Please make bug reports self-contained. Don't link off to other threads for the majority of the information.

For the record:

Audrius Butkevicius asked:

Maybe I am completely missing out something, but here it goes:

I understand that net.Listen("tcp", ":1234") - is v4 and v6, as the stack is unspecified.
But why on earth is net.Listen("tcp", "") listening on v6 [::]:1234?
Yet why is net.Listen("tcp", "") only listening on v4, even if the same interface has a v6 address?

Most of the software I used (nginx for example) listens only on v4 when given, which I think makes perfect sense, as that means all v4 interfaces.
Same way it only listens to v6 when [::]:80 is specified.

This complicates matters, as I am making an application where the user can specify a listen address I either have to add -tcp4 or -tcp6 flags to work out the stack the user is interested in, or do a bunch of .IsIP4()/.isIP6() to work out the users actual intent from the provided address.

Can someone shed some light on this?


@quentinmit quentinmit changed the title net: no docs about the behavior of announcing or listening on IP dual stack net: net.Listen("tcp", "") also listens on IPv6 Nov 1, 2016
@quentinmit quentinmit added this to the Go1.9 milestone Nov 1, 2016
Copy link

@quentinmit quentinmit commented Nov 1, 2016

/cc @rsc

I think there is an implementation bug here; an IPv4 address should cause an IPv4 listener to be created, even if it's

That said... I can't imagine many users actually care about listening on all v4 interfaces but not v6 interfaces. They almost certainly want :1234 instead.

Copy link
Contributor Author

@mikioh mikioh commented Nov 17, 2016


I don't think it's a good idea to mix two issues here. I just wanted to update documentation. Can you please open a new issue for the new behavior?

Copy link

@gopherbot gopherbot commented Jun 14, 2017

CL mentions this issue.

@gopherbot gopherbot closed this in 071908f Jun 14, 2017
gopherbot pushed a commit that referenced this issue Jun 22, 2017
This change clarifies the documentation on Listen and ListenPacket to
avoid unnecessary confusion about how the arguments for the connection
setup functions are used to make connections.

Also replaces "name" or "hostname" with "host name" when the term
implies the use of DNS.

Updates #17613.
Updates #17614.
Updates #17615.
Fixes #17616.
Updates #17738.
Updates #17956.

Change-Id: I0bad2e143207666f2358d397fc076548ee6c3ae9
Reviewed-by: Ian Lance Taylor <>
@golang golang locked and limited conversation to collaborators Jun 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.