I've never seriously read golang code in my life before and I'm so deeply confused right now

I'm literally *one stack frame deep* and I'm seeing code that makes me want to scream

no sensible language would allow this to work even when SERVER_PORT isn't set:

port := os.Getenv("SERVER_PORT")
lis, err := net.Listen("tcp", "localhost:"+port)

> If the port in the address parameter is empty or "0", as in "127.0.0.1:" or "[::1]:0", a port number is automatically chosen. The Addr method of Listener can be used to discover the chosen port.

:hhHHHAAAH:

@iliana@cybre.space For bonus points, did you know that the `Addr` may not actually be what it's listening on?

That is to say, the following code can panic in some cases:

conn, err := net.Listen("tcp", ":8080")
if err != nil {
log.Fatal("couldn't listen")
}
_, err = net.Dial("tcp", conn.Addr().String())
if err != nil {
panic("this does happen in some cases")
}

Follow

For anyone curious about the details, it's basically "ipv6" github.com/moby/moby/issues/33

In go's defence, the behaviour was fixed in go1.9, so it probably can't panic anymore (whoops, didn't realize that until I looked it up now) github.com/golang/go/issues/18

· · Web · 0 · 0 · 0
Sign in to participate in the conversation
Wobscale Social

wobscale.social - a server for friends of the Wob, affiliated with Wobscale Technologies