azmq icon indicating copy to clipboard operation
azmq copied to clipboard

Publisher message is lost if sent just after bind

Open enrico-samknows opened this issue 2 years ago • 2 comments

Hi, I'm trying your library and I see a strange issue. If I do this:

auto socket = std::string("ipc://test");
publisher_.bind(socket);
auto sent = publisher_.send(boost::asio::buffer(topic + " " + payload));

the message is never received by the subscriber.

If I add a

std::this_thread::sleep_for(std::chrono::seconds(1));

after .bind(), it works. Why is that? How can I wait for the bind to be over before sending the message, without relying on an hardcoded time delay? Is there an .async_wait of some kind?

Thanks.

enrico-samknows avatar Jun 30 '22 16:06 enrico-samknows

I think your seeing the slow-joiner syndrome, which is not unique to azmq, but a characteristic of the pub/sub pattern.

This is discussed a bit in the guide here https://zguide.zeromq.org/docs/chapter5/#Representing-State-as-Key-Value-Pairs

The azmq unit test injects a similar delay: https://github.com/zeromq/azmq/blob/e0058a38976399006f535a9010d29e763b43fcd8/test/socket/main.cpp#L627

aboseley avatar Jul 03 '22 22:07 aboseley

Thanks, I studied the underlying syscalls with strace and I realised the client needs to subscribe before getting data. It makes sense. Do you think 200ms is a 100% safe delay? Or should I wait 1000ms, as in the example?

enrico-samknows avatar Jul 04 '22 08:07 enrico-samknows