-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
tokio-sync mpsc poll_ready irrevocably reserves slot #898
Comments
In fact, it's even a little worse than that I think? Is this code okay? impl Handle {
fn poll_ready(&mut self) -> Poll<(), Error> {
for s in &mut self.shards {
try_ready!(s.poll_ready());
}
Ok(Async::Ready(()))
}
} Imagine that the second shard returns |
This is intentional. A work around is to add a wrapper around the buffered |
@carllerche can you speak to whether calling Also, I still think it'd be useful to "return" a reserved slot if you decide not to send after all. |
@jonhoo calling |
I don't know the best way to expose a fn that explicitly revokes capacity w/o dropping the handle. Thoughts? |
|
I was thinking about this recently and I think having a disarm function would be a good idea. Since the default can be a noop it should be relatively safe to add. There are already some generic wrappers involving In particular |
Version
tokio-sync 0.1.1
Description
I have a sharded "write handle" that contains multiple
mpsc::Sender
s. When a user wants to send data, they firstpoll_ready
on the write handle, which internally doespoll_ready
on all itsSender
s, and when they getReady
they provide the write handle with the data they wish to send. The write handle shards that data, and only sends to the shards for which there is data in the request. This means that if the user only provides data that goes to a few of the shards, every remaining shard will now have a slot permanently taken.This can be represented by the following test, which fails as
tx2.poll_ready()
returnsNotReady
:This behavior is pretty unfortunate, and it's not clear how to fix it. My write handle implements
tower::Service
, sopoll_ready
doesn't know what data is going to be sent, so it can't onlypoll_ready
the necessarySender
s. And there is no way forcall
to "un-poll" the slots that it has already reserved. As far as I can tell, the only way to work around this is to clone the sender and then drop the old one to force it to let go of its slot? Can we do better?The text was updated successfully, but these errors were encountered: