-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZMQ_REQ_CORRELATE may not work when sent messages are not received immediately #1695
Comments
FredTreg
added a commit
to FredTreg/libzmq
that referenced
this issue
Mar 20, 2016
Problem: when using ZMQ_REQ_RELAXED + ZMQ_REQ_CORRELATE and two 'send' are executed in a row and no server is available at the time of the sends, then the internal request_id used to identify messages gets corrupted and the two messages end up with the same request_id. The correlation no longer works in that case and you may end up with the wrong message. Solution: make a copy of the request_id instance member before sending it down the pipe.
FredTreg
added a commit
to FredTreg/libzmq
that referenced
this issue
Mar 20, 2016
Problem: when using ZMQ_REQ_RELAXED + ZMQ_REQ_CORRELATE and two 'send' are executed in a row and no server is available at the time of the sends, then the internal request_id used to identify messages gets corrupted and the two messages end up with the same request_id. The correlation no longer works in that case and you may end up with the wrong message. Solution: make a copy of the request_id instance member before sending it down the pipe.
hintjens
added a commit
that referenced
this issue
Mar 24, 2016
Fixed issue #1695 (ZMQ_REQ_CORRELATE)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
Considering a REQ socket with both the
ZMQ_REQ_RELAXED
andZMQ_REQ_CORRELATE
options enabled, if two messages are sent in a row, then the nextrecv()
done on the socket will fail to receive the answer corresponding to the second message (as would otherwise be expected) if the server connected to the REQ socket is bound only after the two messages are sent. Answer from the first message is received instead.The example code pasted at the end of this issue reproduces this behavior.
Notes:
ZMQ_REQ_RELAXED
option cannot be used either.ZMQ_REQ_CORRELATE
. The incorrect correlation issue may arise with other setups such as when using aninproc://
ROUTER server bound before the messages are sent but slow to respond to them.Analysis
By checking the message parts sent, I could track the issue down to this piece of code in the
req.cpp
file:The
request_id
in the code above is a member variable and is not copied in memory to a new variable when fed to theinit_data
method. So multiple sent messages share the same variable.As a consequence, when issuing two
send()
in a row, the first message may not have been sent yet down the wire when the second message is sent to the pipe. Therequest_id
value of the first message is then overridden by therequest_id
value of the second message before being wired. Sent messages no longer have unique ids and can no longer be correlated.Solutions
terminate()
that was used prior to the fixing of defect ZMQ_REQ_RELAXED does not work #1690 was too much as it would close the send pipe forever.request_id
before sending it to the pipe. Though this solution has a small performance impact, it is easy to understand and works whatever the - potentially unknown and changing - intrisics of zmq are.Unless someone comments on these solutions, I will submit a pull request implementing solution 2. in a couple of days.
Example code
Example code demonstrating the issue (without error handling to make it clearer):
The text was updated successfully, but these errors were encountered: