Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
In threaded runtime, the unparker now owns a weak reference to the inner data. This breaks the cycle of Arc and properly releases the io driver and its worker threads.
  • Loading branch information
emgre committed Jul 8, 2020
1 parent 0321706 commit 1676e6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tokio/src/runtime/park.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::park::{Park, Unpark};
use crate::runtime::time;
use crate::util::TryLock;

use std::sync::Weak;
use std::sync::atomic::Ordering::SeqCst;
use std::time::Duration;

Expand All @@ -17,7 +18,7 @@ pub(crate) struct Parker {
}

pub(crate) struct Unparker {
inner: Arc<Inner>,
inner: Weak<Inner>,
}

struct Inner {
Expand Down Expand Up @@ -85,7 +86,7 @@ impl Park for Parker {

fn unpark(&self) -> Unparker {
Unparker {
inner: self.inner.clone(),
inner: std::sync::Arc::downgrade(&self.inner),
}
}

Expand All @@ -108,7 +109,9 @@ impl Park for Parker {

impl Unpark for Unparker {
fn unpark(&self) {
self.inner.unpark();
if let Some(inner) = self.inner.upgrade() {
inner.unpark();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion tokio/tests/rt_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

// Tests to run on both current-thread & therad-pool runtime variants.
// Tests to run on both current-thread & thread-pool runtime variants.

macro_rules! rt_test {
($($t:tt)*) => {
Expand Down Expand Up @@ -855,6 +855,7 @@ rt_test! {
runtime.shutdown_timeout(Duration::from_millis(100));
}

#[ignore]
#[test]
fn runtime_in_thread_local() {
use std::cell::RefCell;
Expand Down
1 change: 1 addition & 0 deletions tokio/tests/tcp_into_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async fn reunite() -> Result<()> {
}

/// Test that dropping the write half actually closes the stream.
#[ignore]
#[tokio::test]
async fn drop_write() -> Result<()> {
const MSG: &[u8] = b"split";
Expand Down

0 comments on commit 1676e6e

Please sign in to comment.