From 91f7a57b82101a0177b9de70294657adf1ce07a0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Feb 2026 07:47:46 -0800 Subject: [PATCH 1/2] Fix cleanup task race that could remove a new producer The spawned unused() cleanup task removes by track name, which could evict a newer producer inserted at the same key after a stale one was replaced. Guard the removal with an identity check so only the original producer instance is evicted. Co-Authored-By: Claude Opus 4.6 --- rs/moq-lite/src/model/broadcast.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rs/moq-lite/src/model/broadcast.rs b/rs/moq-lite/src/model/broadcast.rs index f4949395c..be44477d9 100644 --- a/rs/moq-lite/src/model/broadcast.rs +++ b/rs/moq-lite/src/model/broadcast.rs @@ -223,7 +223,12 @@ impl BroadcastConsumer { let state = self.state.clone(); web_async::spawn(async move { producer.unused().await; - state.lock().producers.remove(&producer.info.name); + let mut state = state.lock(); + if let Some(current) = state.producers.remove(&producer.info.name) { + if !current.is_clone(&producer) { + state.producers.insert(current.info.name.clone(), current); + } + } }); consumer From a95f7969a10bec4ce8b759b216c1e33bcd35d41b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 12 Feb 2026 08:13:09 -0800 Subject: [PATCH 2/2] just fix --- rs/moq-lite/src/model/broadcast.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rs/moq-lite/src/model/broadcast.rs b/rs/moq-lite/src/model/broadcast.rs index be44477d9..53b202687 100644 --- a/rs/moq-lite/src/model/broadcast.rs +++ b/rs/moq-lite/src/model/broadcast.rs @@ -224,10 +224,10 @@ impl BroadcastConsumer { web_async::spawn(async move { producer.unused().await; let mut state = state.lock(); - if let Some(current) = state.producers.remove(&producer.info.name) { - if !current.is_clone(&producer) { - state.producers.insert(current.info.name.clone(), current); - } + if let Some(current) = state.producers.remove(&producer.info.name) + && !current.is_clone(&producer) + { + state.producers.insert(current.info.name.clone(), current); } });