playbin3: Fix deadlock while selecting streams going to playing

In the following backtrace for the deadlock, we can see that:

- In T8 `uridecodebin3` is exposing a new pad, in `pad_added_cb`,
  `playbin3` is trying to get `GST_PLAY_BIN3_LOCK` in the callback. This
  threads holds its `SELECTION_LOCK` in F17 `reconfigure_output_stream`,
  which is looks right `decodebin3` is handling its selection state
  in that code path

- In T7 `playbin3` holds the `GST_PLAY_BIN3_LOCK` when calling
  `gst_element_post_message` in `gst_play_bin3_send_event` which is
  not necessary in that section of the code.

``` bt
Thread 8 (Thread 0x7f0b78ee36c0 (LWP 2952467) "multiqueue0:src"):
 #0  futex_wait (private=0, expected=2, futex_word=0x1fa6d60) at ../sysdeps/nptl/futex-internal.h:146
 #1  __GI___lll_lock_wait (futex=futex@entry=0x1fa6d60, private=0) at lowlevellock.c:49
 #2  0x00007f0b858cd46a in lll_mutex_lock_optimized (mutex=0x1fa6d60) at pthread_mutex_lock.c:48
 #3  ___pthread_mutex_lock (mutex=0x1fa6d60) at pthread_mutex_lock.c:128
 #4  0x00007f0b7e665720 in pad_added_cb (uridecodebin=0x1fb4050, pad=0x7f0b54022060, playbin=0x1fb00e0) at ../subprojects/gst-plugins-base/gst/playback/gstplaybin3.c:2463
 #5  0x00007f0b85c00060 in g_closure_invoke (closure=0x1fa9eb0, return_value=0x0, n_param_values=2, param_values=0x7f0b78ee1dd0, invocation_hint=0x7f0b78ee1d50) at ../gobject/gclosure.c:832
 #6  0x00007f0b85c2cf66 in signal_emit_unlocked_R.isra.0 (node=node@entry=0x1c5bf30, detail=detail@entry=0, instance=instance@entry=0x1fb4050, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7f0b78ee1dd0) at ../gobject/gsignal.c:3796
 #7  0x00007f0b85c1d4da in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7f0b78ee1f90) at ../gobject/gsignal.c:3549
 #8  0x00007f0b85c1d6f3 in g_signal_emit (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>) at ../gobject/gsignal.c:3606
 #9  0x00007f0b85e20c3e in gst_element_add_pad (element=0x1fb4050, pad=0x7f0b54022060) at ../subprojects/gstreamer/gst/gstelement.c:802
 #10 0x00007f0b7e632620 in add_output_pad (dec=0x1fb4050, target_pad=0x7f0b6400fda0) at ../subprojects/gst-plugins-base/gst/playback/gsturidecodebin3.c:717
 #11 0x00007f0b7e632788 in db_pad_added_cb (element=0x1fb8020, pad=0x7f0b6400fda0, dec=0x1fb4050) at ../subprojects/gst-plugins-base/gst/playback/gsturidecodebin3.c:736
 #12 0x00007f0b85c00060 in g_closure_invoke (closure=0x1fb7fc0, return_value=0x0, n_param_values=2, param_values=0x7f0b78ee2300, invocation_hint=0x7f0b78ee2280) at ../gobject/gclosure.c:832
 #13 0x00007f0b85c2cf66 in signal_emit_unlocked_R.isra.0 (node=node@entry=0x1c5bf30, detail=detail@entry=0, instance=instance@entry=0x1fb8020, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7f0b78ee2300) at ../gobject/gsignal.c:3796
 #14 0x00007f0b85c1d4da in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7f0b78ee24c0) at ../gobject/gsignal.c:3549
 #15 0x00007f0b85c1d6f3 in g_signal_emit (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>) at ../gobject/gsignal.c:3606
 #16 0x00007f0b85e20c3e in gst_element_add_pad (element=0x1fb8020, pad=0x7f0b6400fda0) at ../subprojects/gstreamer/gst/gstelement.c:802
 #17 0x00007f0b7e6260b4 in reconfigure_output_stream (output=0x7f0b5400def0, slot=0x7f0b64013dd0, msg=0x7f0b78ee26b8) at ../subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c:3086
 #18 0x00007f0b7e623700 in check_slot_reconfiguration (dbin=0x1fb8020, slot=0x7f0b64013dd0) at ../subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c:2455
 #19 0x00007f0b7e623e62 in multiqueue_src_probe (pad=0x7f0b6001e600, info=0x7f0b78ee2930, slot=0x7f0b64013dd0) at ../subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c:2544
 #20 0x00007f0b85e53aaa in probe_hook_marshal (hook=0x7f0b74040500, data=0x7f0b78ee28c0) at ../subprojects/gstreamer/gst/gstpad.c:3669
 #21 0x00007f0b85c88a3e in g_hook_list_marshal (hook_list=0x7f0b6001e698, may_recurse=1, marshaller=0x7f0b85e53786 <probe_hook_marshal>, data=0x7f0b78ee28c0) at ../glib/ghook.c:674
 #22 0x00007f0b85e541be in do_probe_callbacks (pad=0x7f0b6001e600, info=0x7f0b78ee2930, defaultval=GST_FLOW_OK) at ../subprojects/gstreamer/gst/gstpad.c:3853
 #23 0x00007f0b85e5ac9c in gst_pad_push_event_unchecked (pad=0x7f0b6001e600, event=0x7f0b64002120, type=GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) at ../subprojects/gstreamer/gst/gstpad.c:5538
 #24 0x00007f0b85e54bc2 in push_sticky (pad=0x7f0b6001e600, ev=0x7f0b78ee2a60, user_data=0x7f0b78ee2ac0) at ../subprojects/gstreamer/gst/gstpad.c:4057
 #25 0x00007f0b85e4a13c in events_foreach (pad=0x7f0b6001e600, func=0x7f0b85e54a8e <push_sticky>, user_data=0x7f0b78ee2ac0) at ../subprojects/gstreamer/gst/gstpad.c:613
 #26 0x00007f0b85e54f91 in check_sticky (pad=0x7f0b6001e600, event=0x7f0b64002120) at ../subprojects/gstreamer/gst/gstpad.c:4116
 #27 0x00007f0b85e5b65e in gst_pad_push_event (pad=0x7f0b6001e600, event=0x7f0b64002120) at ../subprojects/gstreamer/gst/gstpad.c:5706
 #28 0x00007f0b7e5888e7 in gst_single_queue_push_one (mq=0x1fbb000, sq=0x7f0b64013b70, object=0x7f0b64002120, allow_drop=0x7f0b78ee2c3c) at ../subprojects/gstreamer/plugins/elements/gstmultiqueue.c:2068
 #29 0x00007f0b7e58a1bc in gst_multi_queue_loop (pad=0x7f0b6001e600) at ../subprojects/gstreamer/plugins/elements/gstmultiqueue.c:2347
 #30 0x00007f0b85e96a36 in gst_task_func (task=0x7f0b64016050) at ../subprojects/gstreamer/gst/gsttask.c:399
 #31 0x00007f0b85e97e41 in default_func (tdata=0x7f0b640138d0, pool=0x1fbe9c0) at ../subprojects/gstreamer/gst/gsttaskpool.c:70
 #32 0x00007f0b85cd1ab2 in g_thread_pool_thread_proxy (data=<optimized out>) at ../glib/gthreadpool.c:352
 #33 0x00007f0b85ccc982 in g_thread_proxy (data=0x7f0b6006f640) at ../glib/gthread.c:831
 #34 0x00007f0b858ca12d in start_thread (arg=<optimized out>) at pthread_create.c:442
 #35 0x00007f0b8594bbc0 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

Thread 7 (Thread 0x7f0b7a7646c0 (LWP 2952434) "multiqueue3:src"):
 #0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
 #1  0x00007f0b85cf470c in g_mutex_lock_slowpath (mutex=0x1fb81d0) at ../glib/gthread-posix.c:1494
 #2  0x00007f0b7e6281a2 in gst_decodebin3_send_event (element=0x1fb8020, event=0x7f0b6800a650) at ../subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c:3561
 #3  0x00007f0b85e23ca3 in gst_element_send_event (element=0x1fb8020, event=0x7f0b6800a650) at ../subprojects/gstreamer/gst/gstelement.c:1994
 #4  0x00007f0b7e63806b in gst_uri_decodebin3_send_event (element=0x1fb4050, event=0x7f0b6800a650) at ../subprojects/gst-plugins-base/gst/playback/gsturidecodebin3.c:2227
 #5  0x00007f0b85e23ca3 in gst_element_send_event (element=0x1fb4050, event=0x7f0b6800a650) at ../subprojects/gstreamer/gst/gstelement.c:1994
 #6  0x00007f0b7e66375a in gst_play_bin3_send_event (element=0x1fb00e0, event=0x7f0b6800a650) at ../subprojects/gst-plugins-base/gst/playback/gstplaybin3.c:1863
 #7  0x00007f0b85e23ca3 in gst_element_send_event (element=0x1fb00e0, event=0x7f0b6800a650) at ../subprojects/gstreamer/gst/gstelement.c:1994
 #8  0x00007f0b85f61b5b in stream_selection_cb (bus=0x1dc2d80, message=0x7f0b68008b00, d=0x1d7de30) at ../subprojects/gst-devtools/validate/gst/validate/gst-validate-scenario.c:2235
 #9  0x00007f0b85c00060 in g_closure_invoke (closure=0x1d2a5b0, return_value=0x0, n_param_values=2, param_values=0x7f0b7a7627b0, invocation_hint=0x7f0b7a762730) at ../gobject/gclosure.c:832
 #10 0x00007f0b85c2cf66 in signal_emit_unlocked_R.isra.0 (node=node@entry=0x1c5e5f0, detail=detail@entry=235, instance=instance@entry=0x1dc2d80, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7f0b7a7627b0) at ../gobject/gsignal.c:3796
 #11 0x00007f0b85c1d4da in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7f0b7a762970) at ../gobject/gsignal.c:3549
 #12 0x00007f0b85c1d6f3 in g_signal_emit (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>) at ../gobject/gsignal.c:3606
 #13 0x00007f0b85e05be9 in gst_bus_sync_signal_handler (bus=0x1dc2d80, message=0x7f0b68008b00, data=0x0) at ../subprojects/gstreamer/gst/gstbus.c:1307
 #14 0x00007f0b85e03834 in gst_bus_post (bus=0x1dc2d80, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbus.c:364
 #15 0x00007f0b85e2436c in gst_element_post_message_default (element=0x1fb00e0, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstelement.c:2127
 #16 0x00007f0b85df42b1 in gst_bin_post_message (element=0x1fb00e0, msg=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbin.c:2789
 #17 0x00007f0b85e24627 in gst_element_post_message (element=0x1fb00e0, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstelement.c:2170
 #18 0x00007f0b85df7c12 in gst_bin_handle_message_func (bin=0x1fb00e0, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbin.c:4041
 #19 0x00007f0b85e61bd3 in gst_pipeline_handle_message (bin=0x1fb00e0, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstpipeline.c:669
 #20 0x00007f0b7e663fa4 in gst_play_bin3_handle_message (bin=0x1fb00e0, msg=0x7f0b68008b00) at ../subprojects/gst-plugins-base/gst/playback/gstplaybin3.c:2030
 #21 0x00007f0b85df5a98 in bin_bus_handler (bus=0x1dc2cc0, message=0x7f0b68008b00, bin=0x1fb00e0) at ../subprojects/gstreamer/gst/gstbin.c:3263
 #22 0x00007f0b85e037f1 in gst_bus_post (bus=0x1dc2cc0, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbus.c:357
 #23 0x00007f0b85e2436c in gst_element_post_message_default (element=0x1fb4050, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstelement.c:2127
 #24 0x00007f0b85df42b1 in gst_bin_post_message (element=0x1fb4050, msg=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbin.c:2789
 #25 0x00007f0b85e24627 in gst_element_post_message (element=0x1fb4050, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstelement.c:2170
 #26 0x00007f0b85df7c12 in gst_bin_handle_message_func (bin=0x1fb4050, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbin.c:4041
 #27 0x00007f0b7e638005 in gst_uri_decode_bin3_handle_message (bin=0x1fb4050, msg=0x7f0b68008b00) at ../subprojects/gst-plugins-base/gst/playback/gsturidecodebin3.c:2218
 #28 0x00007f0b85df5a98 in bin_bus_handler (bus=0x1dc2e40, message=0x7f0b68008b00, bin=0x1fb4050) at ../subprojects/gstreamer/gst/gstbin.c:3263
 #29 0x00007f0b85e037f1 in gst_bus_post (bus=0x1dc2e40, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbus.c:357
 #30 0x00007f0b85e2436c in gst_element_post_message_default (element=0x1fb8020, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstelement.c:2127
 #31 0x00007f0b85df42b1 in gst_bin_post_message (element=0x1fb8020, msg=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstbin.c:2789
 #32 0x00007f0b85e24627 in gst_element_post_message (element=0x1fb8020, message=0x7f0b68008b00) at ../subprojects/gstreamer/gst/gstelement.c:2170
 #33 0x00007f0b7e61ee43 in sink_event_function (sinkpad=0x7f0b6400f8c0, dbin=0x1fb8020, event=0x7f0b6c097870) at ../subprojects/gst-plugins-base/gst/playback/gstdecodebin3.c:1450
 #34 0x00007f0b85f51122 in gst_validate_pad_monitor_downstream_event_check (pad_monitor=0x7f0b6c094a80, parent=0x1fb8020, event=0x7f0b6c097870, handler=0x7f0b7e61e797 <sink_event_function>) at ../subprojects/gst-devtools/validate/gst/validate/gst-validate-pad-monitor.c:2101
 #35 0x00007f0b85f535bf in gst_validate_pad_monitor_sink_event_full_func (pad=0x7f0b6400f8c0, parent=0x1fb8020, event=0x7f0b6c097870) at ../subprojects/gst-devtools/validate/gst/validate/gst-validate-pad-monitor.c:2406
 #36 0x00007f0b85f537fa in gst_validate_pad_monitor_sink_event_func (pad=0x7f0b6400f8c0, parent=0x1fb8020, event=0x7f0b6c097870) at ../subprojects/gst-devtools/validate/gst/validate/gst-validate-pad-monitor.c:2418
 #37 0x00007f0b85e5c523 in gst_pad_send_event_unchecked (pad=0x7f0b6400f8c0, event=0x7f0b6c097870, type=GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) at ../subprojects/gstreamer/gst/gstpad.c:5940
 #38 0x00007f0b85e5ae65 in gst_pad_push_event_unchecked (pad=0x7f0b6400f650, event=0x7f0b6c097870, type=GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) at ../subprojects/gstreamer/gst/gstpad.c:5573
 #39 0x00007f0b85e54bc2 in push_sticky (pad=0x7f0b6400f650, ev=0x7f0b7a763620, user_data=0x7f0b7a763680) at ../subprojects/gstreamer/gst/gstpad.c:4057
 #40 0x00007f0b85e4a13c in events_foreach (pad=0x7f0b6400f650, func=0x7f0b85e54a8e <push_sticky>, user_data=0x7f0b7a763680) at ../subprojects/gstreamer/gst/gstpad.c:613
 #41 0x00007f0b85e54f91 in check_sticky (pad=0x7f0b6400f650, event=0x7f0b6c097870) at ../subprojects/gstreamer/gst/gstpad.c:4116
 #42 0x00007f0b85e5b65e in gst_pad_push_event (pad=0x7f0b6400f650, event=0x7f0b6c097870) at ../subprojects/gstreamer/gst/gstpad.c:5706
 #43 0x00007f0b85e523e7 in event_forward_func (pad=0x7f0b6400f650, data=0x7f0b7a763820) at ../subprojects/gstreamer/gst/gstpad.c:3130
 #44 0x00007f0b85e521e3 in gst_pad_forward (pad=0x7f0b6004f180, forward=0x7f0b85e522bd <event_forward_func>, user_data=0x7f0b7a763820) at ../subprojects/gstreamer/gst/gstpad.c:3084
 #45 0x00007f0b85e525ab in gst_pad_event_default (pad=0x7f0b6004f180, parent=0x7f0b6400f650, event=0x7f0b6c097870) at ../subprojects/gstreamer/gst/gstpad.c:3181
 #46 0x00007f0b85e5c523 in gst_pad_send_event_unchecked (pad=0x7f0b6004f180, event=0x7f0b6c097870, type=GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) at ../subprojects/gstreamer/gst/gstpad.c:5940
 #47 0x00007f0b85e5ae65 in gst_pad_push_event_unchecked (pad=0x7f0b64008360, event=0x7f0b6c097870, type=GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) at ../subprojects/gstreamer/gst/gstpad.c:5573
 #48 0x00007f0b85e54bc2 in push_sticky (pad=0x7f0b64008360, ev=0x7f0b7a763a60, user_data=0x7f0b7a763ac0) at ../subprojects/gstreamer/gst/gstpad.c:4057
 #49 0x00007f0b85e4a13c in events_foreach (pad=0x7f0b64008360, func=0x7f0b85e54a8e <push_sticky>, user_data=0x7f0b7a763ac0) at ../subprojects/gstreamer/gst/gstpad.c:613
 #50 0x00007f0b85e54f91 in check_sticky (pad=0x7f0b64008360, event=0x7f0b6c097870) at ../subprojects/gstreamer/gst/gstpad.c:4116
 #51 0x00007f0b85e5b65e in gst_pad_push_event (pad=0x7f0b64008360, event=0x7f0b6c097870) at ../subprojects/gstreamer/gst/gstpad.c:5706
 #52 0x00007f0b7e5888e7 in gst_single_queue_push_one (mq=0x7f0b60076540, sq=0x7f0b6c093300, object=0x7f0b6c097870, allow_drop=0x7f0b7a763c3c) at ../subprojects/gstreamer/plugins/elements/gstmultiqueue.c:2068
 #53 0x00007f0b7e58a1bc in gst_multi_queue_loop (pad=0x7f0b64008360) at ../subprojects/gstreamer/plugins/elements/gstmultiqueue.c:2347
 #54 0x00007f0b85e96a36 in gst_task_func (task=0x7f0b6c072050) at ../subprojects/gstreamer/gst/gsttask.c:399
 #55 0x00007f0b85e97e41 in default_func (tdata=0x7f0b6c093ef0, pool=0x1fbe9c0) at ../subprojects/gstreamer/gst/gsttaskpool.c:70
 #56 0x00007f0b85cd1ab2 in g_thread_pool_thread_proxy (data=<optimized out>) at ../glib/gthreadpool.c:352
 #57 0x00007f0b85ccc982 in g_thread_proxy (data=0x7f0b70033800) at ../glib/gthread.c:831
 #58 0x00007f0b858ca12d in start_thread (arg=<optimized out>) at pthread_create.c:442
 #59 0x00007f0b8594bbc0 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
```

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5982>
This commit is contained in:
Thibault Saunier 2023-07-30 17:06:41 -04:00 committed by GStreamer Marge Bot
parent a4156ebeee
commit e17c7a0b7f
3 changed files with 22 additions and 1 deletions

View file

@ -952,6 +952,7 @@ validate.test.mse.segment_future_past_nomse
validate.test.nle.urisource.play
validate.test.playbin.check_active_stream
validate.test.playbin3.ignore_raw_audio_from_demuxer
validate.test.playbin3.intensive_state_change_selecting_stream
validate.test.playbin3.ogv_vp8
validate.test.playbin3.sourcebin_check_mixed_static_and_dyanmic_pads
validate.test.rtp.h264.payloader_fail_nego_force_profile

View file

@ -0,0 +1,19 @@
set-globals,
media_dir="$(test_dir)/../../../medias",
file="file://$(media_dir)/defaults/matroska/flac_jpeg.1.mkv"
meta,
handles-states=true,
ignore-eos=true,
args = {
"playbin3 uri=$(file) name=p video-sink=\"$(videosink)\" audio-sink=\"$(audiosink)\"",
}
foreach, i=[0, 40],
actions = {
"select-streams, indexes=0",
"play",
"set-state, state=null",
}
stop;

View file

@ -1857,10 +1857,11 @@ gst_play_bin3_send_event (GstElement * element, GstEvent * event)
/* Don't reconfigure playsink just yet, until the streams-selected
* message(s) tell us as streams become active / available */
GST_PLAY_BIN3_UNLOCK (playbin);
/* Send this event directly to uridecodebin, so it works even
* if uridecodebin didn't add any pads yet */
res = gst_element_send_event (playbin->uridecodebin, event);
GST_PLAY_BIN3_UNLOCK (playbin);
return res;
}