zeromq / chumak

Pure Erlang implementation of ZeroMQ Message Transport Protocol.
Mozilla Public License 2.0
197 stars 47 forks source link

router-dealer packet loss on dealer reconnect #38

Closed pavels closed 3 years ago

pavels commented 3 years ago

I don't know if this is chumak or zeromq spec limitation but this happens:

Assume we have router and dealers (the main reason for me for using this pattern is message passing - i have one router and multiple dealers and any of these can send message at any time). Dealers connects to topics on router - each dealer has it's own topic.

Now current implementation in chumak works the way, that if multiple dealers connect to same topic, message sent to one topic is routed in round-robin fashion probably as a form of load balancing.

If something happens on the dealer side that results in reconnect (dealer is restarted) now the router doesn't know that happened and there becomes two sockets available on that same topic (the old one, which is now invalid, and the new one). If you send message to such topic and the invalid socket is chosen, the OS replies that that socket is actually closed (as the dealer side replies that such socket doesn't exist) and that chumak removes the socket from the topic.

Problem is, that this way 1 message is always lost when reconnect of the dealer happens. I understand that this is how sockets behave, you can't know that the socket is actually closed unless you try to send something, but it would be nice that if that happens, the message is resent to another dealer probably (if available) instead of it being silently lost.

drozzy commented 3 years ago

Have you looked at some of these reliable techniques? https://zguide.zeromq.org/docs/chapter5/

pavels commented 3 years ago

Ok, this seems like intentional behavior then.

Thank you