rt: fix storing Runtime in thread-local (#2011)

Storing a `Runtime` value in a thread-local resulted in a panic due to
the inability to access the parker.

This fixes the bug by skipping parking if it fails. In general, there
isn't much that we can do besides not parking.

Fixes #593
This commit is contained in:
Carl Lerche
2019-12-22 13:03:44 -08:00
committed by GitHub
parent 7b53b7b659
commit adc5186ebd
6 changed files with 41 additions and 11 deletions
+18
View File
@@ -617,6 +617,24 @@ rt_test! {
assert_ok!(drop_rx.recv());
}
#[test]
fn runtime_in_thread_local() {
use std::cell::RefCell;
use std::thread;
thread_local!(
static R: RefCell<Option<Runtime>> = RefCell::new(None);
);
thread::spawn(|| {
R.with(|cell| {
*cell.borrow_mut() = Some(rt());
});
let _rt = rt();
}).join().unwrap();
}
async fn client_server(tx: mpsc::Sender<()>) {
let mut server = assert_ok!(TcpListener::bind("127.0.0.1:0").await);