Skip to content
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

Surprising behavior from mpsc channels when only using try_ methods #861

Closed
nwoeanhinnogaehr opened this issue Mar 12, 2018 · 0 comments
Closed

Comments

@nwoeanhinnogaehr
Copy link
Contributor

Once a bounded channel has been filled and cleared using only try_send and try_next, it remains in a broken state. From here calling try_send always reports that the queue is full, where as try_next always reports that it is empty. This behavior is not found with std::sync::mpsc.

See the following example (0.2.0-alpha):

use futures::channel::mpsc;
fn main() {
    let (mut tx, mut rx) = mpsc::channel(1);
    println!("{:?}", tx.try_send("hello")); // Ok(())
    println!("{:?}", tx.try_send("hello")); // Ok(())
    println!("{:?}", rx.try_next()); // Ok(Some("hello"))
    println!("{:?}", rx.try_next()); // Ok(Some("hello"))
    println!("{:?}", tx.try_send("hello")); // Err(TrySendError { kind: Full })
    println!("{:?}", rx.try_next()); // Err(TryRecvError)
    println!("{:?}", tx.try_send("hello")); // Err(TrySendError { kind: Full })
    println!("{:?}", rx.try_next()); // Err(TryRecvError)
}
nwoeanhinnogaehr added a commit to nwoeanhinnogaehr/futures-rs that referenced this issue Mar 13, 2018
Fixed by moving calls to unpark_one and dec_num_messages into next_message
so that calling them cannot be missed (as it was with try_next).

Closes rust-lang#861
cramertj pushed a commit that referenced this issue Mar 13, 2018
Fixed by moving calls to unpark_one and dec_num_messages into next_message
so that calling them cannot be missed (as it was with try_next).

Closes #861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant