Skip to content

Commit 507186d

Browse files
authored
rt: drop runtime before driver during shutdown (tokio-rs#155)
1 parent 31b9ceb commit 507186d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/driver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Drop for Driver {
126126
while self.num_operations() > 0 {
127127
// If waiting fails, ignore the error. The wait will be attempted
128128
// again on the next loop.
129-
_ = self.wait();
129+
let _ = self.wait();
130130
self.tick();
131131
}
132132
}

src/runtime/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ pub struct Runtime {
2424

2525
/// Tokio runtime, always current-thread
2626
rt: tokio::runtime::Runtime,
27+
28+
/// This is here for drop order reasons.
29+
///
30+
/// We can't unset the driver in the runtime drop method, because the inner runtime needs to
31+
/// be dropped first so that there are no tasks running.
32+
///
33+
/// The rust drop order rules guarantee that the inner runtime will be dropped first, and
34+
/// this last.
35+
_driver_guard: RuntimeContextGuard,
2736
}
2837

2938
/// Spawns a new asynchronous task, returning a [`JoinHandle`] for it.
@@ -80,6 +89,7 @@ impl Runtime {
8089
uring_fd: driver_fd,
8190
local,
8291
rt,
92+
_driver_guard: RuntimeContextGuard,
8393
})
8494
}
8595

@@ -114,7 +124,9 @@ impl Runtime {
114124
}
115125
}
116126

117-
impl Drop for Runtime {
127+
struct RuntimeContextGuard;
128+
129+
impl Drop for RuntimeContextGuard {
118130
fn drop(&mut self) {
119131
CONTEXT.with(|rc| rc.unset_driver())
120132
}

0 commit comments

Comments
 (0)