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

A potential mpsc::channel bug #48927

Closed
UncP opened this issue Mar 11, 2018 · 3 comments
Closed

A potential mpsc::channel bug #48927

UncP opened this issue Mar 11, 2018 · 3 comments

Comments

@UncP
Copy link

UncP commented Mar 11, 2018

rustc 1.25.0-nightly (73ac5d6a8 2018-01-11)

use std::thread;
use std::sync::mpsc;
use std::time::Duration;

fn main() {
	let (tx, rx) = mpsc::channel::<u32>();

	let r_handle = thread::spawn(move || {
		match rx.recv_timeout(Duration::from_secs(10)){
			Err(mpsc::RecvTimeoutError::Timeout) => {}
			_ => assert!(false),
		}
                 // next line panics every time.
		rx.recv_timeout(Duration::from_secs(10)).unwrap();
	});

	let t_handle = thread::spawn(move || {
		thread::sleep(Duration::from_secs(2));
		let _ = tx.clone();
		thread::sleep(Duration::from_secs(10));
	});

	r_handle.join().unwrap();
	t_handle.join().unwrap();
}
  1. receiver calls recv_timeout
  2. sender clone itself
  3. recv_timeout returns timeout
  4. receiver calls recv_timeout the second time
  5. boom!

2018-03-11 1 58 49

This is what I know, when sender calls clone, it will call inherit_blocker, and then change to_wake in it. The first recv_timeout returns timeout, when the second recv_timeout is called, it will panic in decrement in shared.rs because it needs to check that to_wake equals 0.

@UncP
Copy link
Author

UncP commented Mar 11, 2018

I also tested the code with the latest rust master, also it panics every time.

@breezewish
Copy link

Similar issues reported previously: #39364

@pietroalbini
Copy link
Member

Closing as a duplicate.

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

3 participants