From 7c909e59a96ac18556308469cb5988f5fb8eaaf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Sun, 19 Dec 2021 19:15:38 +0100 Subject: [PATCH] utils/togglerecord: fix race condition in sink_chain when segment is pending In `sink_chain` when the Segment is pending, attempting to lock rec state could lead to a dead lock because the stream state is already locked while the main stream state was not locked. --- utils/togglerecord/src/togglerecord/imp.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/togglerecord/src/togglerecord/imp.rs b/utils/togglerecord/src/togglerecord/imp.rs index 36074b90..766869b3 100644 --- a/utils/togglerecord/src/togglerecord/imp.rs +++ b/utils/togglerecord/src/togglerecord/imp.rs @@ -1216,6 +1216,12 @@ impl ToggleRecord { }; let out_running_time = { + let main_state = if stream != self.main_stream { + Some(self.main_stream.state.lock()) + } else { + None + }; + let mut state = stream.state.lock(); if state.discont_pending { @@ -1260,6 +1266,7 @@ impl ToggleRecord { // Unlock before pushing drop(state); + drop(main_state); for e in events.drain(..) { stream.srcpad.push_event(e);