mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user