net: clean shutdown of fetch thread (#38421)

The fetch thread is currently not shut down, meaning it is one of the
threads counted in the "threads are still running after shutdown (bad)"
counter shown when Servo has shut-down.

This PR introduces a mechanism to start, and shut-down, one fetch thread
per process that requires one.

Testing: WPT tests and unit tests(for font context). Also manually
tested loading and closing "about:blank": this change indeed brings down
the count of threads still running after shutdown by one.

Fixes: https://github.com/servo/servo/issues/34887

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
Gregory Terzian 2025-08-07 17:01:30 +08:00 committed by GitHub
parent ad805e3110
commit b23cf9c6cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 71 additions and 11 deletions

View file

@ -9,8 +9,8 @@ mod font_context {
use std::collections::HashMap;
use std::ffi::OsStr;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::{Arc, Once};
use std::thread;
use app_units::Au;
@ -23,7 +23,7 @@ mod font_context {
SystemFontServiceProxySender, fallback_font_families,
};
use ipc_channel::ipc::{self, IpcReceiver};
use net_traits::ResourceThreads;
use net_traits::{ResourceThreads, exit_fetch_thread, start_fetch_thread};
use parking_lot::Mutex;
use servo_arc::Arc as ServoArc;
use style::ArcSlice;
@ -36,6 +36,8 @@ mod font_context {
use stylo_atoms::Atom;
use webrender_api::{FontInstanceKey, FontKey, IdNamespace};
static INIT: Once = Once::new();
struct TestContext {
context: FontContext,
system_font_service: Arc<MockSystemFontService>,
@ -53,6 +55,9 @@ mod font_context {
let mock_compositor_api = CrossProcessCompositorApi::dummy();
let proxy_clone = Arc::new(system_font_service_proxy.to_sender().to_proxy());
INIT.call_once(|| {
start_fetch_thread(&mock_resource_threads.core_thread);
});
Self {
context: FontContext::new(proxy_clone, mock_compositor_api, mock_resource_threads),
system_font_service,