Skip to content

Race condition in futures::sync::mpsc #909

Closed
@simmons

Description

@simmons

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 a Sender::try_send() happens concurrently with a Receiver close/drop, it's possible for try_send() to return Ok(()) even though the item can never be received and will not be dropped until the Sender is dropped. My expectation was to receive an error matching Err(ref e) if e.is_disconnected(). The Receiver Drop implementation closes the channel and drains any items present, but this can apparently happen just before the Sender 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 the oneshot::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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions