Skip to content

Race condition in task communication causes deadlocks #15761

Closed
@carllerche

Description

@carllerche

Repro:

extern crate time;

use std::io::IoResult;
use std::io::timer::Timer;
use std::sync::Future;

fn repro() -> IoResult<()> {
    let (tx, rx): (SyncSender<&'static str>, Receiver<&'static str>) = sync_channel(3);

    let mut f = Future::spawn(proc() {
        let mut timer = try!(Timer::new());
        let tick = timer.periodic(10000);

        loop {
            println!("select; {}", time::precise_time_ns());
            select! {
                _ = tick.recv() => {
                    fail!("nope, received tick first; {}", time::precise_time_ns());
                },
                msg = rx.recv() => {
                    println!("Received msg; {}", msg);

                    if msg == "hi2u" {
                        break;
                    }
                }
            }
        }

        Ok(())
    });

    tx.try_send("zomg").unwrap();
    tx.try_send("hi2u").unwrap();

    f.get()
}

pub fn main() {
    let mut i = 0u;
    loop {
        i += 1;
        println!("starting iter {}; {}", i, time::precise_time_ns());
        repro().unwrap();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions