Skip to content

Commit

Permalink
net: shutdown async runtime on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed May 30, 2020
1 parent 34a41f5 commit fa76516
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions components/net/http_loader.rs
Expand Up @@ -59,7 +59,7 @@ use tokio::prelude::{future, Future, Stream};
use tokio::runtime::Runtime;

lazy_static! {
pub static ref HANDLE: Mutex<Runtime> = Mutex::new(Runtime::new().unwrap());
pub static ref HANDLE: Mutex<Option<Runtime>> = Mutex::new(Some(Runtime::new().unwrap()));
}

/// The various states an entry of the HttpCache can be in.
Expand Down Expand Up @@ -95,7 +95,10 @@ impl HttpState {
history_states: RwLock::new(HashMap::new()),
http_cache: RwLock::new(HttpCache::new()),
http_cache_state: Mutex::new(HashMap::new()),
client: create_http_client(tls_config, HANDLE.lock().unwrap().executor()),
client: create_http_client(
tls_config,
HANDLE.lock().unwrap().as_ref().unwrap().executor(),
),
}
}
}
Expand Down Expand Up @@ -1613,7 +1616,7 @@ fn http_network_fetch(
let timing_ptr3 = context.timing.clone();
let url1 = request.url();
let url2 = url1.clone();
HANDLE.lock().unwrap().spawn(
HANDLE.lock().unwrap().as_mut().unwrap().spawn(
res.into_body()
.map_err(|_| ())
.fold(res_body, move |res_body, chunk| {
Expand Down
7 changes: 5 additions & 2 deletions components/net/resource_thread.rs
Expand Up @@ -152,7 +152,7 @@ fn create_http_states(
http_cache_state: Mutex::new(HashMap::new()),
client: create_http_client(
create_tls_config(&certs, ALPN_H2_H1),
HANDLE.lock().unwrap().executor(),
HANDLE.lock().unwrap().as_ref().unwrap().executor(),
),
};

Expand All @@ -165,7 +165,7 @@ fn create_http_states(
http_cache_state: Mutex::new(HashMap::new()),
client: create_http_client(
create_tls_config(&certs, ALPN_H2_H1),
HANDLE.lock().unwrap().executor(),
HANDLE.lock().unwrap().as_ref().unwrap().executor(),
),
};

Expand Down Expand Up @@ -591,6 +591,9 @@ impl CoreResourceManager {
// or a short timeout has been reached.
self.thread_pool.exit();

// Shut-down the async runtime used by fetch workers.
drop(HANDLE.lock().unwrap().take());

debug!("Exited CoreResourceManager");
}

Expand Down

0 comments on commit fa76516

Please sign in to comment.