-
Notifications
You must be signed in to change notification settings - Fork 633
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
Race condition in futures::sync::mpsc #909
Comments
I looked through the
Just to test, I added a |
Fix a bug where messages sent into a channel at the same time as the `Receiver` is dropped are never removed. Fixes rust-lang#909
It looks like there's a race condition in the MPSC implementation in
futures 0.1.19
, unless my understanding of the intended behavior is incorrect. If aSender::try_send()
happens concurrently with aReceiver
close/drop, it's possible fortry_send()
to returnOk(())
even though the item can never be received and will not be dropped until theSender
is dropped. My expectation was to receive an error matchingErr(ref e) if e.is_disconnected()
. TheReceiver
Drop
implementation closes the channel and drains any items present, but this can apparently happen just before theSender
thinks it has successfully enqueued the item.I wrote a small program to stress-test this scenario and demonstrate the bug:
https://github.com/simmons/mpsc-stress
I discovered this behavior while stress testing a program which implements a synchronous API by sending a command +
oneshot::Sender
to a future's MPSC, which processes the command and sends the oneshot when complete. When the described race occurs, the sending thread would deadlock while hopelessly waiting forever for theoneshot::Receiver
to either receive or indicate disconnection.If I get a chance in the next few days, I'll see if I can root-cause the problem. (Unless I'm told that my expectation is incorrect.)
The text was updated successfully, but these errors were encountered: