Recovering from zmq.error.ZMQError: Address already in use

Pratik Mandrekar picture Pratik Mandrekar · Oct 3, 2013 · Viewed 23.5k times · Source

I hit Ctrl-C while running a PAIR pattern (non-blocking client servers) connection with ZMQ. Later when I tried running the REQ-REP (blocking client single server connection) pattern, I keep getting the Address already in use error. I have tried running netstat with netstat -ltnp | grep :<my port> but that does not list any process.

So who exactly is using this address?

Also how does one gracefully shutdown socket connections like these?

Answer

jorgen picture jorgen · Dec 1, 2013

Question 1:

If you do sudo netstat -ltnp, on a Linux type operating system, you will most probably see the process owning the port. Kill it with kill -9 <pid>.

Question 2:

When you exit the program, close your sockets and then call zmq_ctx_destroy(). This destroys the context. See http://zguide.zeromq.org/page:all#toc17 for more info.