From 677184a0e6895802e267ae83208a6220ad4f6aac Mon Sep 17 00:00:00 2001 From: webbeef Date: Mon, 14 Jul 2025 08:43:45 -0700 Subject: [PATCH] BroadcastChannel: cleanup routers when closing tabs (#38046) BroadcastChannel uses 2 hash maps in the constellation and they were not kept properly in sync. Also fixed a logic error where `Option>` was not considered empty when being `None`. Testing: These warnings should not happen anymore: [2025-07-14T03:54:22Z WARN constellation::constellation] No sender for broadcast router: (4,1) [2025-07-14T03:33:59Z WARN constellation_traits::structured_data] Attempt to broadcast structured serialized data including ImageBitmap (should never happen). [2025-07-14T03:33:59Z WARN constellation_traits::structured_data] Attempt to broadcast structured serialized data including MessagePort (should never happen). [2025-07-14T03:33:59Z WARN constellation_traits::structured_data] Attempt to broadcast structured serialized data including OffscreenCanvas (should never happen). [2025-07-14T03:33:59Z WARN constellation_traits::structured_data] Attempt to broadcast structured serialized data including ReadableStream (should never happen). [2025-07-14T03:33:59Z WARN constellation_traits::structured_data] Attempt to broadcast structured serialized data including WritableStream (should never happen). [2025-07-14T03:33:59Z WARN constellation_traits::structured_data] Attempt to broadcast structured serialized data including TransformStream (should never happen). Signed-off-by: webbeef --- components/constellation/constellation.rs | 6 ++++++ components/shared/constellation/structured_data/mod.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 8b478f51684..c9f93d9ab11 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -2000,6 +2000,12 @@ where if self.broadcast_routers.remove(&router_id).is_none() { warn!("Attempt to remove unknown broadcast-channel router."); } + // Also remove the router_id from the broadcast_channels list. + for channels in self.broadcast_channels.values_mut() { + for routers in channels.values_mut() { + routers.retain(|router| router != &router_id); + } + } } /// Add a new broadcast router. diff --git a/components/shared/constellation/structured_data/mod.rs b/components/shared/constellation/structured_data/mod.rs index 89ca1466bc8..4590a7b70e8 100644 --- a/components/shared/constellation/structured_data/mod.rs +++ b/components/shared/constellation/structured_data/mod.rs @@ -47,7 +47,7 @@ pub struct StructuredSerializedData { impl StructuredSerializedData { fn is_empty(&self, val: Transferrable) -> bool { fn is_field_empty(field: &Option>) -> bool { - field.as_ref().is_some_and(|h| h.is_empty()) + field.as_ref().is_none_or(|h| h.is_empty()) } match val { Transferrable::ImageBitmap => is_field_empty(&self.transferred_image_bitmaps),