summaryrefslogtreecommitdiffstats
path: root/tokio/src/runtime
diff options
context:
space:
mode:
authorCarl Lerche <me@carllerche.com>2019-12-21 13:19:52 -0800
committerGitHub <noreply@github.com>2019-12-21 13:19:52 -0800
commit3d1b4b30585532e9708e322e1a0876d2933af71a (patch)
treeb46bf489507bed9adcfe7bf75cf9f413de8e9808 /tokio/src/runtime
parent8656b7b8eb6f3635ec40694eb71f14fb84211e05 (diff)
rt: fix spawn_blocking from spawn_blocking (#2006)
Nested spawn_blocking calls would result in a panic due to the necessary context not being setup. This patch sets the blocking pool context from within a blocking pool. Fixes #1982
Diffstat (limited to 'tokio/src/runtime')
-rw-r--r--tokio/src/runtime/blocking/pool.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs
index 6c23daec..43f94a48 100644
--- a/tokio/src/runtime/blocking/pool.rs
+++ b/tokio/src/runtime/blocking/pool.rs
@@ -244,32 +244,31 @@ impl Spawner {
builder = builder.stack_size(stack_size);
}
- let inner = self.inner.clone();
+ let spawner = self.clone();
builder
.spawn(move || {
- inner.run();
+ run_thread(spawner);
- // Make sure `inner` drops first to ensure that the shutdown_rx
- // sees all refs to `Inner` are dropped when the `shutdown_rx`
- // resolves.
- drop(inner);
drop(shutdown_tx);
})
.unwrap();
}
}
-impl Inner {
- fn run(&self) {
- let _io = io::set_default(&self.io_handle);
+fn run_thread(spawner: Spawner) {
+ spawner.enter(|| {
+ let inner = &*spawner.inner;
+ let _io = io::set_default(&inner.io_handle);
- time::with_default(&self.time_handle, &self.clock, || {
- self.spawner.enter(|| self.run2());
+ time::with_default(&inner.time_handle, &inner.clock, || {
+ inner.spawner.enter(|| inner.run());
});
- }
+ });
+}
- fn run2(&self) {
+impl Inner {
+ fn run(&self) {
if let Some(f) = &self.after_start {
f()
}