From 87e32f571ae32fab5a051bdaecddc83ff916c136 Mon Sep 17 00:00:00 2001 From: QuantumEntangledAndy Date: Thu, 21 Sep 2023 11:23:20 +0700 Subject: [PATCH] Cancel threads in stream witha drop guard --- src/rtsp/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rtsp/mod.rs b/src/rtsp/mod.rs index db4c892..30e8305 100644 --- a/src/rtsp/mod.rs +++ b/src/rtsp/mod.rs @@ -649,6 +649,7 @@ async fn stream_run( log::info!("{}: Avaliable at {}", name, paths.join(", ")); let stream_cancel = CancellationToken::new(); + let drop_guard = stream_cancel.clone().drop_guard(); let mut set = JoinSet::new(); // Wait for new media client data to come in from the factory while let Some(mut client_data) = client_rx.recv().await { @@ -861,6 +862,7 @@ async fn stream_run( // Cancel any remaining threads that are trying to send data // Although it should be finished already when the appsrcs are dropped stream_cancel.cancel(); + drop(drop_guard); while set.join_next().await.is_some() {} log::trace!("Stream done"); AnyResult::Ok(())