Skip to content
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

rt: drop runtime before driver during shutdown #155

Merged
merged 1 commit into from
Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl Drop for Driver {
while self.num_operations() > 0 {
// If waiting fails, ignore the error. The wait will be attempted
// again on the next loop.
_ = self.wait();
let _ = self.wait();
self.tick();
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub struct Runtime {

/// Tokio runtime, always current-thread
rt: tokio::runtime::Runtime,

/// This is here for drop order reasons.
///
/// We can't unset the driver in the runtime drop method, because the inner runtime needs to
FrankReh marked this conversation as resolved.
Show resolved Hide resolved
/// be dropped first so that there are no tasks running.
///
/// The rust drop order rules guarantee that the inner runtime will be dropped first, and
/// this last.
_driver_guard: RuntimeContextGuard,
}

/// Spawns a new asynchronous task, returning a [`JoinHandle`] for it.
Expand Down Expand Up @@ -80,6 +89,7 @@ impl Runtime {
uring_fd: driver_fd,
local,
rt,
_driver_guard: RuntimeContextGuard,
})
}

Expand Down Expand Up @@ -114,7 +124,9 @@ impl Runtime {
}
}

impl Drop for Runtime {
struct RuntimeContextGuard;

impl Drop for RuntimeContextGuard {
fn drop(&mut self) {
CONTEXT.with(|rc| rc.unset_driver())
}
Expand Down