[zeromq-dev] PUB/SUB overload: duplicate messages
[zeromq-dev] PUB/SUB overload: duplicate messages
At my job, I’m starting to use zeromq, a nice library for message passing and queueing. Yesterday, I was trying to figure out the reason of a strange issue (I tweeted about that): inside a simple function, I send some messages to a client via zeromq, but the client does get the right number of messages, but the content is repeated, duplicated.
I looked on Google, and it found this thread on the [zeromq-dev] mailing list (join it, it’s really interesting). In its response, Pieter explains that using a static buffer is bad for you, because of concurrent access problems to the buffer (data in the buffer are not copied, you just pass a reference to be accessed later by the I/O threads) and posts a workaround. Another response points to the “Working with Messages” paragraph in the guide: docs are always good! :D
To confirm this, I can tell you my application was able to successfully send several empty messages: the buffer was copied in the same moment I memset’d it.
This problem is present with the cppzmq C++ wrapper too, specifically with this method: dropping that (really thin) wrapper and using libzmq is better.
So, how can you fix it? Just copy the content of the static buffer inside message's data.
The more you know…