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: Listen("tcp", ":123456789") works #11715

Closed
pierrre opened this issue Jul 14, 2015 · 7 comments
Closed

net: Listen("tcp", ":123456789") works #11715

pierrre opened this issue Jul 14, 2015 · 7 comments
Milestone

Comments

@pierrre
Copy link

pierrre commented Jul 14, 2015

CL: https://golang.org/cl/12213

Go version: go1.4.2 linux/amd64 (same result with Go 1.5beta1)
My code:

package main

import (
    "fmt"
    "net"
)

func main() {
    l, err := net.Listen("tcp", ":123456789")
    if err != nil {
        panic(err)
    }
    fmt.Println(l.Addr())
}

It prints: [::]:52501 (always this port)
What I expected: it should return an error.

If I use port ":66666", it prints: panic: listen tcp: invalid port 66666

@jnjackins
Copy link
Contributor

This will happen for any ports higher than 0xFFFFFF. dtoi fails for inputs larger than that, which causes parsePort to take a different error path.

The error message for ports >= 0xFFFFFF (16777215) on darwin is a bit more reasonable:

panic: listen tcp: lookup tcp/16777215: nodename nor servname provided, or not known

@jnjackins
Copy link
Contributor

Actually, I get a decent error message on linux as well:

$ uname -a
Linux foo.bar.com 2.6.32-504.23.4.el6.x86_64 #1 SMP Fri May 29 10:16:43 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
$ ./test2 
panic: listen tcp: unknown port tcp/16777215

@jnjackins
Copy link
Contributor

I mailed https://go-review.googlesource.com/#/c/12213, although I don't know if it's an acceptable fix and I'm sure it's not important for go1.5.

@jnjackins
Copy link
Contributor

Oh, I've realized now that I read your message wrong from the beginning. I thought you were getting a strange error message, but you're not getting an error at all for the higher port. I wasn't reproducing it correctly, as I was cross-compiling for linux from darwin. I see the real issue now when I compile and run from linux.

@gopherbot
Copy link

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

@mikioh
Copy link
Contributor

mikioh commented Jul 21, 2015

@jnjackins,

Please open a new issue for consistent error messages. This issue needs to focus on the behavior of Listen w/ invalid arguments.

@bradfitz bradfitz added this to the Go1.6 milestone Jul 21, 2015
@gopherbot
Copy link

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

@mikioh mikioh closed this as completed in b50b21d Nov 1, 2015
@golang golang locked and limited conversation to collaborators Nov 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants