Skip to content

Commit

Permalink
net: avoid race in driver shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
zaharidichev committed Oct 17, 2020
1 parent e88e64b commit bad1d29
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tokio/src/io/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) struct Driver {
poll: mio::Poll,

/// State shared between the reactor and the handles.
inner: Arc<Inner>,
inner: Option<Arc<Inner>>,
}

/// A reference to an I/O driver
Expand Down Expand Up @@ -106,11 +106,11 @@ impl Driver {
events: Some(mio::Events::with_capacity(1024)),
resources: slab,
poll,
inner: Arc::new(Inner {
inner: Some(Arc::new(Inner {
registry,
io_dispatch: allocator,
waker,
}),
})),
})
}

Expand All @@ -122,7 +122,7 @@ impl Driver {
/// to bind them to this event loop.
pub(crate) fn handle(&self) -> Handle {
Handle {
inner: Arc::downgrade(&self.inner),
inner: Arc::downgrade(self.inner.as_ref().expect("driver closed")),
}
}

Expand Down Expand Up @@ -181,6 +181,8 @@ impl Driver {

impl Drop for Driver {
fn drop(&mut self) {
let inner = self.inner.take().expect("driver closed");
drop(inner);
self.resources.for_each(|io| {
// If a task is waiting on the I/O resource, notify it. The task
// will then attempt to use the I/O resource and fail due to the
Expand Down

0 comments on commit bad1d29

Please sign in to comment.