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

Channel select panics "passed a receiver that wasn't selected" when using different clones of the same receiver #1096

Open
ChocolateLoverRaj opened this issue Mar 23, 2024 · 2 comments

Comments

@ChocolateLoverRaj
Copy link

The correct id gets selected but when I try to do the operation it fails. I think this is a bug because I expect cloning a receiver to still be the same receiver.

Way of reproducing:

use crossbeam_channel::{Select, unbounded};

fn main() {
    let (tx, rx) = unbounded::<u32>();
    tx.send(123).unwrap();
    let mut select = Select::new();
    let id = select.recv(&rx);
    let operation = select.select();
    println!("recv id: {}. selected id: {}.", id, operation.index());
    operation.recv(&rx.clone()).unwrap();
}
[dependencies]
crossbeam-channel = "0.5.12"
@taiki-e
Copy link
Member

taiki-e commented Mar 24, 2024

Currently, we are using a reference to the sender as an identifier, but I guess we can fix this by using the pointer that the sender points to as an identifier.

let ptr = s as *const Sender<_> as *const u8;

pub(crate) struct Sender<C> {
counter: NonNull<Counter<C>>,

@ChocolateLoverRaj
Copy link
Author

Can the bug label be added to this? This is a bug imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants