Panic occurs when using tokio::task::spawn
in Drop
when running in a LocalSet
#5794
-
I've got a repository demonstrating the problem if you want a very simple reproduction case: https://github.com/acheronfail/tokio-local The Problem I'm running an application which is trying to be completely single-threaded. It does this by using I've noticed that one of the libraries I depend on uses I think this representation might help understand the issue:
I'm not sure how to solve this, since I don't control the code inside the What I find confusing is that the panic is that there's Have I missed something obvious? Or is this an issue with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
So, the unexpected panic occurs when starting the runtime like so: let runtime = Builder::new_current_thread().enable_all().build().unwrap();
LocalSet::new().block_on(async_main(SpawnMethod::SpawnLocal, DropMethod::Spawn));
// thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', src/main.rs:88:34 However, I've noticed some interesting behaviour which may be a hint. Wrapping the // runtime.block_on
let runtime = Builder::new_current_thread().enable_all().build().unwrap();
runtime.block_on(LocalSet::new().run_until(async_main(SpawnMethod::SpawnLocal, DropMethod::Spawn)));
// thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', src/main.rs:88:34 Still panics. However, this - which was unexpected to me - stops the panic from occurring: // runtime.block_on with wrapped LocalSet
let runtime = Builder::new_current_thread().enable_all().build().unwrap();
runtime.block_on(async {
LocalSet::new()
.run_until(async_main(SpawnMethod::SpawnLocal, DropMethod::Spawn))
.await;
});
// no panic 🎉 So, this is at least a workaround. |
Beta Was this translation helpful? Give feedback.
-
You get a panic if you call The |
Beta Was this translation helpful? Give feedback.
A is equivalent to this: