-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Tokio LocalSet can no longer be stored in thread_local #4973
Comments
Thanks for reporting this! I have a few ideas as to what did this. I'm going to go and run a bisect. |
This is probably caused by #4765, but I don't really understand how this was not already an issue. Perhaps that PR somehow changes the order in which the thread-locals are destroyed? Anyway, I've opened a PR that should fix this. |
Version tokio 1.21.2 Platform x86_64-unknown-linux-gnu Description seems met a similar problem. Here is my code, is the error expected?
And I don't understand why Here is the link to the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e26d1f993906627a219d304e849cc70b // src/main.rs
use tokio::runtime::Runtime;
use tokio::task::LocalSet;
thread_local! {
pub static LOCAL_SET: TokioLocalSet = TokioLocalSet::new();
}
pub struct TokioLocalSet {
rt: Runtime,
local: LocalSet,
}
impl TokioLocalSet {
pub fn new() -> TokioLocalSet {
TokioLocalSet {
rt: tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap(),
local: LocalSet::new(),
}
}
async fn inner_method(&self) {
self.local
.run_until(async move {
tokio::task::spawn_local(async {});
})
.await
}
pub fn method(&self) {
self.rt.block_on(self.inner_method());
}
}
fn main1(){
// will panic
LOCAL_SET.with(|f|{
f.method();
});
}
fn main2(){
// work well
let ls = TokioLocalSet::new();
ls.method();
}
fn main3(){
// work well
let ls = TokioLocalSet::new();
ls.method();
LOCAL_SET.with(|f|{
f.method();
});
} # Cargo.toml
[package]
name = "tokio_local_set"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { version = "1.21.2", features = ["full"] } |
Version
tokio 1.21.0
Platform
aarch64-unknown-linux-gnu
x86_64-unknown-linux-gnu
Description
The following code runs fine with
1.20.1
but panics in1.21.0
.I tried this code:
I expected to see this happen:
The code should run as normal.
Instead, this happened:
The text was updated successfully, but these errors were encountered: