layout: Shut down style thread-pool when exiting a content process / shutting down the Constellation (#38924)

To ensure a clean-shutdown of Servo, we need to shutdown our internal
threading before deinit. This shuts down the style thread pool either
using the constellation(in single-process mode), or when a content
process exits.

Testing: Manual testing by opening a window, opening and closing
multiple tabs, and closing the window, with a sleep added before deinit
and a sample taken to ensure the loose threads previously noticed are
gone.
Fixes: part of https://github.com/servo/servo/issues/30849

---------

Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
Gregory Terzian 2025-08-26 21:10:03 +08:00 committed by GitHub
parent 7339e2b421
commit 08b9eb818c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 10 additions and 0 deletions

1
Cargo.lock generated
View file

@ -1514,6 +1514,7 @@ dependencies = [
"servo_config",
"servo_rand",
"servo_url",
"stylo",
"stylo_traits",
"tracing",
"webgpu",

View file

@ -55,6 +55,7 @@ servo_config = { path = "../config" }
servo_rand = { path = "../rand" }
servo_url = { path = "../url" }
stylo_traits = { workspace = true }
stylo = { workspace = true }
tracing = { workspace = true, optional = true }
webgpu = { path = "../webgpu" }
webgpu_traits = { workspace = true }

View file

@ -165,6 +165,7 @@ use servo_config::prefs::{self, PrefValue};
use servo_config::{opts, pref};
use servo_rand::{Rng, ServoRng, SliceRandom, random};
use servo_url::{Host, ImmutableOrigin, ServoUrl};
use style::global_style_data::StyleThreadPool;
#[cfg(feature = "webgpu")]
use webgpu::swapchain::WGPUImageMap;
#[cfg(feature = "webgpu")]
@ -755,6 +756,10 @@ where
}
self.handle_shutdown();
if !opts::get().multiprocess {
StyleThreadPool::shutdown();
}
// Shut down the fetch thread started above.
exit_fetch_thread();
join_handle

View file

@ -107,6 +107,7 @@ use servo_geometry::{
use servo_media::ServoMedia;
use servo_media::player::context::GlContext;
use servo_url::ServoUrl;
use style::global_style_data::StyleThreadPool;
use webgl::WebGLComm;
#[cfg(feature = "webgpu")]
pub use webgpu;
@ -1281,6 +1282,8 @@ pub fn run_content_process(token: String) {
.join()
.expect("Failed to join on the BHM background thread.");
StyleThreadPool::shutdown();
// Shut down the fetch thread started above.
exit_fetch_thread();
fetch_thread_join_handle