From 578c52fe2b28978867ef9b07d5c7fa8a0211d9c1 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 30 May 2025 13:44:16 +0200 Subject: [PATCH] constellation: Wait for canvas thread to shut down before shutting down system font service (#37182) The canvas thread might need access to the system font service before it shuts down. Ensure that it finishes shutting down before triggering the shutdown of the system font service. This should avoid issues where canvas tries to access fonts right before shutting down. Fixes: #36849. Testing: Since this fixes a flaky crash on shutdown, there isn't a good way to write a test for it. Signed-off-by: Martin Robinson --- components/canvas/canvas_paint_thread.rs | 5 ++++- components/constellation/constellation.rs | 10 +++++++++- components/shared/canvas/lib.rs | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/components/canvas/canvas_paint_thread.rs b/components/canvas/canvas_paint_thread.rs index 82a221d560d..efadbf8d577 100644 --- a/components/canvas/canvas_paint_thread.rs +++ b/components/canvas/canvas_paint_thread.rs @@ -97,7 +97,10 @@ impl<'a> CanvasPaintThread<'a> { let canvas_data = canvas_paint_thread.create_canvas(size); creator.send(canvas_data).unwrap(); }, - Ok(ConstellationCanvasMsg::Exit) => break, + Ok(ConstellationCanvasMsg::Exit(exit_sender)) => { + let _ = exit_sender.send(()); + break; + }, Err(e) => { warn!("Error on CanvasPaintThread receive ({})", e); break; diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 65d94641322..866791268f9 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -2758,7 +2758,11 @@ where } debug!("Exiting Canvas Paint thread."); - if let Err(e) = self.canvas_sender.send(ConstellationCanvasMsg::Exit) { + let (canvas_exit_sender, canvas_exit_receiver) = unbounded(); + if let Err(e) = self + .canvas_sender + .send(ConstellationCanvasMsg::Exit(canvas_exit_sender)) + { warn!("Exit Canvas Paint thread failed ({})", e); } @@ -2800,6 +2804,10 @@ where debug!("Exiting GLPlayer thread."); WindowGLContext::get().exit(); + // Wait for the canvas thread to exit before shutting down the font service, as + // canvas might still be using the system font service before shutting down. + let _ = canvas_exit_receiver.recv(); + debug!("Exiting the system font service thread."); self.system_font_service.exit(); diff --git a/components/shared/canvas/lib.rs b/components/shared/canvas/lib.rs index 826db54b0f6..df6b0854b9e 100644 --- a/components/shared/canvas/lib.rs +++ b/components/shared/canvas/lib.rs @@ -21,5 +21,5 @@ pub enum ConstellationCanvasMsg { sender: Sender<(CanvasId, ImageKey)>, size: Size2D, }, - Exit, + Exit(Sender<()>), }