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

Semantics of Receiver::try_recv() differ between Sender and SyncSender #34711

Closed
GGist opened this issue Jul 7, 2016 · 1 comment
Closed

Comments

@GGist
Copy link
Contributor

GGist commented Jul 7, 2016

I tried this code:

use std::sync::mpsc::{self};
use std::mem;

fn main() {
    let (sync_send, sync_recv) = mpsc::sync_channel(1);

    sync_send.send(()).unwrap();
    mem::drop(sync_send);

    println!("{:?}", sync_recv.try_recv());

    //-----------------------------------------//

    let (send, recv) = mpsc::channel();

    send.send(()).unwrap();
    mem::drop(send);

    println!("{:?}", recv.try_recv());
}

I expected to see this happen:

Ok(())
Ok(())

Instead, this happened:

Err(Disconnected)
Ok(())

Notes

I see that in the docs there is a comment under the Receiver::recv() method that states "However, since channels are buffered, messages sent before the disconnect will still be properly received." but this comment is not duplicated under Receiver::try_recv().

However, I tried tracing the specific Receiver used in conjunction with SyncSenders which led me to here where it looks like an eager check for a disconnect while ignoring possible data that is still buffered in the Queue. Is this intended?

@alexcrichton
Copy link
Member

Oh dear, this definitely looks like a bug to me! If you've got a fix in mind, feel free to send a PR of course!

bors added a commit that referenced this issue Jul 10, 2016
Check for data in Receiver::try_recv before reporting disconnect

Fixes #34711

r? @alexcrichton
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

2 participants