From 08b9eb818c446b3fdc6403c26e516933807037c6 Mon Sep 17 00:00:00 2001 From: Gregory Terzian <2792687+gterzian@users.noreply.github.com> Date: Tue, 26 Aug 2025 21:10:03 +0800 Subject: [PATCH] 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> --- Cargo.lock | 1 + components/constellation/Cargo.toml | 1 + components/constellation/constellation.rs | 5 +++++ components/servo/lib.rs | 3 +++ 4 files changed, 10 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e5bba184db3..32b8d709533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1514,6 +1514,7 @@ dependencies = [ "servo_config", "servo_rand", "servo_url", + "stylo", "stylo_traits", "tracing", "webgpu", diff --git a/components/constellation/Cargo.toml b/components/constellation/Cargo.toml index a982bcbfe73..e149947f2f1 100644 --- a/components/constellation/Cargo.toml +++ b/components/constellation/Cargo.toml @@ -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 } diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index b4bb8de3a4b..4c0d244ac5e 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -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 diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 9b3fff5f2bf..6d62e07eed7 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -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