libzmq icon indicating copy to clipboard operation
libzmq copied to clipboard

Problem: There is no API or mechanism to manage ROUTER socket's connected clients

Open reza-ebrahimi opened this issue 8 years ago • 14 comments

There are 10 Clients (DEALER sockets) that are connected to a ROUTER socket, if all clients send message to ROUTER socket and in ROUTER side for sending reply response to exactly such a DEALER it might know about its handle, to do this there is no API to manage DEALER handles in ROUTER side, so manager should do some tasks like adding, removing or query a handle.

reza-ebrahimi avatar Jan 23 '17 07:01 reza-ebrahimi

Isn't the identity used for that purpose?

bluca avatar Jan 23 '17 08:01 bluca

@bluca Yes, of course! but identity doesn't enough in dealing with some situations, for example, one problem happened when a DEALER socket lost (disconnected) its connection, so that socket identity still be in ROUTER socket side and exists their identity state in application code, if you send any data to disconnected DEALER socket it will face with access violation error. so in cause of the error, application code doesn't know about disconnected socket state or doesn't notified about that to consider another tasks such as removing socket identity handle.

I think this is a ZeroMQ kernel task to provide a identity manager in ROUTER socket side and do proper tasks (adding, removing, querying), by now there is no notifying mechanism from ROUTER socket about disconnection of ROUTER clients (ex. DEALER sockets).

reza-ebrahimi avatar Jan 23 '17 20:01 reza-ebrahimi

Isn't ROUTER_MANDATORY https://github.com/zeromq/libzmq/blob/master/doc/zmq_setsockopt.txt#L705 a solution for that already? It will return an error in such cases

bluca avatar Jan 24 '17 22:01 bluca

The socket monitor will send a disconnect event and the application can remove the DEALER. Isn't that all you need?

Edit: sorry, the EVENT_DISCONNECTED only includes the endpoint, which works for a single connection but not for a ROUTER sockets with 10 DEALERS. See #2306. So I should have asked: Would #2306 solve your problem?

mrvn avatar Feb 02 '17 11:02 mrvn

Yes, That is! I need to know which peer is disconnected, to do this zeromq might provide me at least peer's identity and another useful information such as socket lost reason:

Disconnection event structure (suggestion):

  • socket identity
  • disconnection reason

reza-ebrahimi avatar Feb 07 '17 17:02 reza-ebrahimi

PRs are most welcome :)

bluca avatar Feb 07 '17 23:02 bluca

If we want to modify zmq monitoring system, we should use ZMQ_PAIR socket, documentation says:

A socket of type ZMQ_PAIR can only be connected to a single peer at any one time. No message routing or filtering is performed on messages sent over a ZMQ_PAIR socket.

in this case we should create and connect multiple instance of ZMQ_PAIR socket based on how many peers connected to ROUTER socket, the problem here is monitor socket only works in inproc protocol scheme, so we cannot connect ZMQ_PAIR socket to a DEALER socket from ROUTER side.

Also using a ZMQ_PAIR socket with ROUTER doesn't give us its peers events, this only works with ROUTER socket itself.

reza-ebrahimi avatar Feb 13 '17 21:02 reza-ebrahimi

Guys, This is requirement that we were looking for in our application as well. Has this been addressed in any form ? Please guide.

nishsharma001 avatar Apr 14 '18 14:04 nishsharma001

It has not - pull requests are welcome

bluca avatar Apr 14 '18 15:04 bluca

Hi We also wanted a solution like this. Is it available now?

nagarajsherigar avatar Apr 30 '19 02:04 nagarajsherigar

A disconnection is notified using [identity, b''] (ie one-message-with-identity-and-empty-string) in pyzmq so you actually know who and when it disconnected. I would assume it's similar in the lower level api.

dbivolaru avatar Aug 11 '19 09:08 dbivolaru

@dbivolaru ,

That only happens if you set appropriate flags for ZMQ_ROUTER_NOTIFY socketopt.

From libzmq/master docs, it seems that this option is still in draft state and not part of the general release.

Did you build libzmq with --enable-drafts option?

If not, is this socketopt out of it's draft state?

Thanks!

rite2hhh avatar Dec 23 '19 21:12 rite2hhh

Any updates or approachs on this? My server with router keep crashing when I try to send msg to disconnected dealer(due to bad internet). NEED HELP !

getarobo avatar Apr 25 '22 08:04 getarobo

Any updates or approachs on this? My server with router keep crashing when I try to send msg to disconnected dealer(due to bad internet). NEED HELP !

NVM setting zmq_router_manadatory to 0 did the trick which is default.

zmq::socket_t cms_router(*ctx, zmq::socket_type::router);
cms_router.set(zmq::sockopt::router_mandatory,0); //<--- ignore error when dealer doesnt exist
cms_router.bind("tcp://*:" + port);

getarobo avatar Apr 27 '22 02:04 getarobo