Auto merge of #26678 - gterzian:shutdown_net_runtime, r=Manishearth

Net: shutdown async runtime on exit

<!-- Please describe your changes on the following line: -->

Shutting down the async runtime as part of exiting the core resource thread.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [ ] `./mach build -d` does not report any errors
- [ ] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
bors-servo 2020-05-30 11:59:20 -04:00 committed by GitHub
commit 5dae012db8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View file

@ -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| {

View file

@ -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");
}