mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-09-02 09:43:48 +00:00
rtprecv: fix race condition on first buffer
When an incoming buffer is received, a deadlock can occur if: 1. 1st buffer is currently being handled by the src pad's task => holds semaphore. 2. 1st buffer reaches downstream AudioDecoder => Latency query. 3. src pad's task still holding semaphore while relaying Latency query. 4. `src_query()` calls `Pad::default()` which calls `iterate_internal_links()`. 5. `iterate_internal_links()` tries to acquire the `state` `Mutex` which is already locked by `handle_push_jitterbuffer()`. This commit temporarily releases the `state` `Mutex` until the semaphore is acquired. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/2466>
This commit is contained in:
parent
e4e14cf5ca
commit
8ec5d0995f
1 changed files with 9 additions and 0 deletions
|
@ -1201,9 +1201,18 @@ impl RtpRecv {
|
||||||
// FIXME: Should block if too many packets are stored here because the source pad task
|
// FIXME: Should block if too many packets are stored here because the source pad task
|
||||||
// is blocked
|
// is blocked
|
||||||
|
|
||||||
|
// Make sure not to deadlock, e.g.:
|
||||||
|
// 1. 1st buffer is currently being handled by the src pad's task => holds semaphore.
|
||||||
|
// 2. 1st buffer reaches downstream AudioDecoder => Latency query.
|
||||||
|
// 3. src pad's task still holding semaphore while relaying Latency query.
|
||||||
|
// 4. `src_query()` calls `Pad::default()` which calls `iterate_internal_links()`.
|
||||||
|
// 5. `iterate_internal_links()` tries to acquire the `state` `Mutex`.
|
||||||
|
// => deadlock.
|
||||||
|
drop(state);
|
||||||
let _src_pad_permit = rtpbin2::get_or_init_runtime()
|
let _src_pad_permit = rtpbin2::get_or_init_runtime()
|
||||||
.expect("initialized in change_state()")
|
.expect("initialized in change_state()")
|
||||||
.block_on(buffer.recv_src_pad.semaphore.acquire());
|
.block_on(buffer.recv_src_pad.semaphore.acquire());
|
||||||
|
state = self.state.lock().unwrap();
|
||||||
|
|
||||||
let mut jb_store = buffer.recv_src_pad.jitter_buffer_store.lock().unwrap();
|
let mut jb_store = buffer.recv_src_pad.jitter_buffer_store.lock().unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue