crossbeam-rs / crossbeam

Tools for concurrent programming in Rust
Apache License 2.0
7.48k stars 471 forks source link

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

Open ChocolateLoverRaj opened 8 months ago

ChocolateLoverRaj commented 8 months ago

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 commented 8 months ago

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.

https://github.com/crossbeam-rs/crossbeam/blob/9e8596105bc9a6b343918b6ad1c9656dc24dc4f9/crossbeam-channel/src/select.rs#L645

https://github.com/crossbeam-rs/crossbeam/blob/9e8596105bc9a6b343918b6ad1c9656dc24dc4f9/crossbeam-channel/src/counter.rs#L38-L39

ChocolateLoverRaj commented 7 months ago

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