pebbe / zmq4

A Go interface to ZeroMQ version 4
BSD 2-Clause "Simplified" License
1.17k stars 163 forks source link

Zmq4 doesn't throw an error when it can't bind to port #66

Closed ckmaresca closed 8 years ago

ckmaresca commented 8 years ago

It seems that zmq4 fails silently when it can't bind to a port because it is already being used. I was expecting that it would throw an error, but this isn't the case, it just ignores the inability to bind to the specified port with no error.

I will see if I can create a patch for this, but I thought I'd log as an issue first.

pebbe commented 8 years ago

Go doesn't throw errors. If bind fails, it returns an error. You have to check that error.

ckmaresca commented 8 years ago

I am checking for an error, no error is generated. I would not be reporting this is there was an error generated.....

responder, err := zmq.NewSocket(zmq.REP)
    if err != nil {
        log.Fatal(err)
    }

An error should be generated if it fails to bind, that is SOP on every networking stack I have ever used in any language. ZMQ4 doesn't generate an error.

Not sure why the semantics of 'throw' vs 'return' are such a huge issue with the Go community - they are basically the same thing - an error is generated when something happens. Anyway, sorry for using improper terminology.

ckmaresca commented 8 years ago

Never mind. I just realize that we should be looking for an error when it binds, not when the socket is created. Sorry for the red herring - the sample code should probably also trap for an error when binding.