Continue polling clients in priority queue if the top is not ready #208
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The fair queue iterator implementation returns
Poll::Pending
when there may be other streams in the priority queue that are ready. Instead of returning after checking only the top stream, continue checking until a stream that returnsPoll::Ready
is found, or all streams have returnedPoll::Pending
and will resubmit themselves to the priority queue when they are ready.I had an issue that can be summarized as the following: I had a server with a pull socket, and two clients connecting with push sockets. One client was fast and sent a message every second. The other client was slow and sent a message every 5 seconds. I expected the server to receiver 5 messages from the fast client, and then a single message from the slow client, and that this would repeat. I observed the eventually, the server would receive only single message from the fast client until a single message from the slow client was received. I debugged this and realized that when the server's fair-queue contained both clients, only the slow client would get polled, leaving the fast client in the queue, even though it was ready.
To reproduce this, I created a demo repo at https://github.com/michael-disalvo/zeromq-demo. Clone it, and run 3 processes:
cargo run --bin server
cargo run --bin client -- -s 1 -m fast
cargo run --bin client -- -s 5 -m slow
The server will print out when it receives each message. At first, every second a message will be received from the fast client. Eventually, it will get stuck and the server will receiver a message from the fast client only every 5 seconds.