Skip to content

Issue with Message Ordering in ZeroMQ PUSH-PULL Using send_multipart #2074

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

Open
fti-ravhad opened this issue Mar 6, 2025 · 3 comments
Open
Labels

Comments

@fti-ravhad
Copy link

Issue with Message Ordering in ZeroMQ PUSH-PULL Using send_multipart

Context:
I am currently working on a multi-threaded module where multiple PUSH sockets send messages to a single PULL socket using ZeroMQ. The messages are sent using the send_multipart method in the following format:

send_socket.send_multipart([msg1, msg2])

  • msg1: JSON data
  • msg2: JPEG byte data

On the receiver side, I am using:
x = receive_socket.recv_multipart() .
I expect x[0] to always contain the JSON data (msg1), and x[1] to contain the JPEG bytes (msg2). However, in some cases, I am receiving the JPEG bytes as x[0], causing message misalignment.
Current Setup:

Messaging Pattern: PUSH-PULL
Multiple PUSH sockets sending data to a single PULL socket

Questions:

  • Is there a more suitable messaging pattern in ZeroMQ that can ensure message ordering while handling multiple senders?
  • Are there any techniques or configurations I should apply to prevent message parts from arriving in the wrong order?

Any insights or suggestions would be greatly appreciated.

Thank you!

@fti-ravhad fti-ravhad changed the title [send_multipart] Issue with Message Ordering in ZeroMQ PUSH-PULL Using send_multipart Mar 6, 2025
@minrk
Copy link
Member

minrk commented Mar 6, 2025

Can you share an example code that reproduces the problem? Libzmq should guarantee that multipart messages are delivered in order in tact, so this should only happen from your description if a recv call is happening but the partial message is not being retrieved.

@fti-ravhad
Copy link
Author

@minrk , Below is the code in sender and receiver side .

The sender processes some calculation and sends the response as below :
Sender side :
self._status_sock.send_multipart([message,image_data])

Receiver side :

request_check = dict(poller.poll(30000))
if request_check.get(on_demand_image_recv) == zmq.POLLIN:
        data = on_demand_image_recv.recv_multipart()

@minrk
Copy link
Member

minrk commented Mar 7, 2025

A more complete example that can reproduce the problem would definitely help. If there are e.g. any threads or other interactions with the sockets, or error handling, that will be relevant.

You can check socket.rvcmore before calling recv_multipart. If that is true, it means that a message has already been partially received and you are going to start receiving a message in the middle.

Generally this would mean an earlier call to recv, or an interrupted call to recv_multipart.

@minrk minrk added the question label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants