zeromq / azmq

C++ language binding library integrating ZeroMQ with Boost Asio
Boost Software License 1.0
319 stars 109 forks source link

Bind sockets with same inproc address on different io_contexts fails #163

Open KnoerleMan opened 4 years ago

KnoerleMan commented 4 years ago

Situation: I have a class with an boost::asio::io_context and multiple azmq::sockets as members. One of the sockets is used as a ROUTER socket and connect to a "external" socket via ipc transport. This socket also calls bind on a hard coded inproc address, specified as followed: "inproc://client_router". Two other sockets (DEALER) of this class will now be connected to the router socket. The connect and bind actions are done when calling the method "open".

Problem: If i use this class and instantiate two objects i can call "open" on the first object without any problems. But when i call "open" on the second object i receive the error message "Address already in use" after bind is called on the router socket. I also checked the storage address of the io_contexts and they are different on both objects. So there seems to be no "magic merging" of the two contexts behind the scenes. But it feels like.

Other Test: When the class is used in two separate processes with one object on each process there is no error when calling open on both.

Question: When reading the zeromq documentation there should be no problem with reused inproc addresses, as far as they are used in different contexts. This seems to be only valid for zeromq contexts created via zmq_init, but not for boost::asio::io_context? Any other suggestions on this problem?

"Solution": When changing the address to a unique one the problem disappears. I still would like to know why this fails with the same address used on different contexts. As stated in the zeromq doc's this should be a valid handling.

Thanks!