diff --git a/tokio/src/runtime/driver.rs b/tokio/src/runtime/driver.rs index 1d90c7945..7715d7030 100644 --- a/tokio/src/runtime/driver.rs +++ b/tokio/src/runtime/driver.rs @@ -70,7 +70,6 @@ cfg_io_driver! { } } - #[cfg_attr(not(feature = "rt-multi-thread"), allow(dead_code))] // some features use this pub(crate) fn shutdown(&mut self) { match self { IoStack::Enabled(v) => v.shutdown(), @@ -230,21 +229,10 @@ cfg_time! { } } - // TODO: tokio-rs/tokio#4990, should the `current_thread` scheduler call this? - cfg_rt_multi_thread! { - pub(crate) fn shutdown(&mut self) { - match self { - TimeDriver::Enabled { driver, handle } => driver.shutdown(handle), - TimeDriver::Disabled(v) => v.shutdown(), - } - } - } - } - - impl Drop for TimeDriver { - fn drop(&mut self) { - if let TimeDriver::Enabled { driver, handle } = self { - driver.shutdown(handle); + pub(crate) fn shutdown(&mut self) { + match self { + TimeDriver::Enabled { driver, handle } => driver.shutdown(handle), + TimeDriver::Disabled(v) => v.shutdown(), } } } @@ -334,10 +322,7 @@ impl Driver { self.inner.park_timeout(duration) } - // TODO: tokio-rs/tokio#4990, should the `current_thread` scheduler call this? - cfg_rt_multi_thread! { - pub(crate) fn shutdown(&mut self) { - self.inner.shutdown() - } + pub(crate) fn shutdown(&mut self) { + self.inner.shutdown() } } diff --git a/tokio/src/runtime/io/mod.rs b/tokio/src/runtime/io/mod.rs index 22d84cbb6..8a8367477 100644 --- a/tokio/src/runtime/io/mod.rs +++ b/tokio/src/runtime/io/mod.rs @@ -230,12 +230,6 @@ impl Driver { } } -impl Drop for Driver { - fn drop(&mut self) { - self.shutdown(); - } -} - impl fmt::Debug for Driver { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Driver") diff --git a/tokio/src/runtime/scheduler/current_thread.rs b/tokio/src/runtime/scheduler/current_thread.rs index b705c786d..c57fddd09 100644 --- a/tokio/src/runtime/scheduler/current_thread.rs +++ b/tokio/src/runtime/scheduler/current_thread.rs @@ -236,6 +236,11 @@ impl Drop for CurrentThread { // Submit metrics core.metrics.submit(&core.spawner.shared.worker_metrics); + // Shutdown the resource drivers + if let Some(driver) = core.driver.as_mut() { + driver.shutdown(); + } + (core, ()) }); }