aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory Terzian <gterzian@users.noreply.github.com>2020-05-27 17:10:54 +0800
committerGregory Terzian <gterzian@users.noreply.github.com>2020-05-30 21:04:34 +0800
commitfa765168b9d14c08950515774e78851aeffacfe2 (patch)
tree9a0b18ec6d42d5f16055f2b18e52f18fa21fece2
parent34a41f57c66d42225f28e62f02c337b46d0e3593 (diff)
downloadservo-fa765168b9d14c08950515774e78851aeffacfe2.tar.gz
servo-fa765168b9d14c08950515774e78851aeffacfe2.zip
net: shutdown async runtime on exit
-rw-r--r--components/net/http_loader.rs9
-rw-r--r--components/net/resource_thread.rs7
2 files changed, 11 insertions, 5 deletions
diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs
index 47ea8f49a47..f12cfa4498c 100644
--- a/components/net/http_loader.rs
+++ b/components/net/http_loader.rs
@@ -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.
@@ -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(),
+ ),
}
}
}
@@ -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| {
diff --git a/components/net/resource_thread.rs b/components/net/resource_thread.rs
index 388cacc77af..28a397e78e6 100644
--- a/components/net/resource_thread.rs
+++ b/components/net/resource_thread.rs
@@ -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(),
),
};
@@ -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(),
),
};
@@ -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");
}