Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 435
Pratik Mandrekar Avatar asked Oct 03 '13 12:10

Pratik Mandrekar


People also ask

How do I know if my ZMQ socket is connected?

No, there's no method in the API to check if a socket is connected. ZeroMq abstracts the network; client and server connections are completely transparent to the peer making the connection.

What is ZMQ port?

ZeroMQ (also spelled ØMQ, 0MQ or ZMQ) is an asynchronous messaging library, aimed at use in distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker; the zero in the name is for zero broker.

What is a ZMQ context?

ZMQ. Context Context is an object serving as a container for all the sockets of a single process. By creating a new context, you start one or more input/output threads: DEFINE context ZMQ.Context. Associated methods: socket()

Is ZMQ asynchronous?

ZeroMQ is an asynchronous network messaging library known for its high performance. It's intended use is for distributed systems as well as concurrent systems.


2 Answers

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.

like image 165
jorgen Avatar answered Sep 18 '22 20:09

jorgen


At this very moment:

reboot 

Next:

start using try: / except: / finally: encapsulation constructors, that will help you to grant a graceful exit from all zmq allocations, incl. all Socket-s' .close() and Context's .term() without any hanging orphan(s) an memory leak(s), even in case any panic button or unhandled exception interrupts your code-execution altogether with losing references to your still hanging, network-hardware bound, instances.

like image 23
user3666197 Avatar answered Sep 19 '22 20:09

user3666197