From a1a3ca9d004719c2b43163a6ea00bfae7588b133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kami=C5=84ski?= Date: Wed, 25 Feb 2026 13:50:12 +0000 Subject: [PATCH] Clean up event subscribers when stopping to listen to a chain --- linera-client/src/chain_listener.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linera-client/src/chain_listener.rs b/linera-client/src/chain_listener.rs index 76d73fac71f5..84d170b1d8e4 100644 --- a/linera-client/src/chain_listener.rs +++ b/linera-client/src/chain_listener.rs @@ -543,6 +543,13 @@ impl ChainListener { Some(cancellation_token) } + fn remove_event_subscriber(&mut self, chain_id: ChainId) { + self.event_subscribers.retain(|_, subscribers| { + subscribers.remove(&chain_id); + !subscribers.is_empty() + }); + } + /// Updates the event subscribers map, and returns all publishing chains we need to listen to. async fn update_event_subscriptions( &mut self, @@ -608,6 +615,7 @@ impl ChainListener { error!(%chain_id, "attempted to drop a non-existent listener"); continue; }; + self.remove_event_subscriber(chain_id); listening_client.stop().await; if let Err(error) = self.context.lock().await.wallet().remove(chain_id).await { error!(%error, %chain_id, "error removing a chain from the wallet"); @@ -638,6 +646,7 @@ impl ChainListener { error!(%chain_id, "attempted to drop a non-existent listener"); continue; }; + self.remove_event_subscriber(chain_id); listening_client.stop().await; continue; };