From d3da30be6d94ca0293d27bc0dd563f1092210b42 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 14 Aug 2023 11:39:49 +0200 Subject: [PATCH] fallbackswitch: prevent deadlocks in chain function Calling schedule_timeout() may result in handle_timeout() being called right away, which will need pad state locks which was still hold in chain(). Part-of: --- utils/fallbackswitch/src/fallbackswitch/imp.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/utils/fallbackswitch/src/fallbackswitch/imp.rs b/utils/fallbackswitch/src/fallbackswitch/imp.rs index e74b79f5..477ee808 100644 --- a/utils/fallbackswitch/src/fallbackswitch/imp.rs +++ b/utils/fallbackswitch/src/fallbackswitch/imp.rs @@ -829,11 +829,14 @@ impl FallbackSwitch { is_active = self.active_sinkpad.lock().as_ref() == Some(pad); } - let mut pad_state = pad_imp.state.lock(); + let pad_state = pad_imp.state.lock(); if pad_state.flushing { debug!(CAT, imp: self, "Flushing"); return Err(gst::FlowError::Flushing); } + // calling schedule_timeout() may result in handle_timeout() being called right away, + // which will need pad state locks, so drop it now to prevent deadlocks. + drop(pad_state); if is_active { if start_running_time @@ -879,6 +882,8 @@ impl FallbackSwitch { } } + let mut pad_state = pad_imp.state.lock(); + if let Some(running_time) = end_running_time { pad_state.current_running_time = Some(running_time); }