Dynamically deleting a stream causes a deadlock

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) A10
• DeepStream Version 6.0
• JetPack Version (valid for Jetson only)
• TensorRT Version 8.01
• NVIDIA GPU Driver Version (valid for GPU only) 470
• Issue Type( questions, new requirements, bugs) bug
• How to reproduce the issue ? (This is for bugs. Including which sample app is using, the configuration files content, the command line used and other details for reproducing)
I added the logic to deepstream-test5 to delete the stream according to deepStream_reference_apps/runtime_source_add_delete .
But gst_element_set_state (ELEM, GST_STATE_NULL) occasionally triggers deadlocks .
I asked the question, but I didn’t get an answer, so I had to ask the question again.

#0  __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
#1  0x00007fdf37ad90f4 in __GI___pthread_mutex_lock (mutex=0x7fdb340013d0) at ../nptl/pthread_mutex_lock.c:115
#2  0x00007fdf3940e87f in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#3  0x00007fdf3940f335 in gst_pad_set_active () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#4  0x00007fdf393ecf0d in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#5  0x00007fdf393ff884 in gst_iterator_fold () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#6  0x00007fdf393eda16 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#7  0x00007fdf393ef95e in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#8  0x00007fdf393efc06 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#9  0x00007fdf39713365 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstvideo-1.0.so.0
#10 0x00007fddfade1f41 in gst_v4l2_video_dec_change_state () from target:/usr/lib/x86_64-linux-gnu/gstreamer-1.0/deepstream/libgstnvvideo4linux2.so
#11 0x00007fdf393f1d5e in gst_element_change_state () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#12 0x00007fdf393f2499 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#13 0x00007fdf393cfa02 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#14 0x00007fdf23e50029 in ?? () from target:/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstplayback.so
#15 0x00007fdf393f1d5e in gst_element_change_state () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#16 0x00007fdf393f2499 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#17 0x00007fdf393cfa02 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#18 0x00007fdf23e6369a in ?? () from target:/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstplayback.so
#19 0x00007fdf393f1d5e in gst_element_change_state () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#20 0x00007fdf393f2499 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#21 0x00007fdf393cfa02 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#22 0x00007fdf393f1d5e in gst_element_change_state () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#23 0x00007fdf393f2045 in gst_element_change_state () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#24 0x00007fdf393f2499 in ?? () from target:/usr/lib/x86_64-linux-gnu/libgstreamer-1.0.so.0
#25 0x0000559350e1e5b2 in stop_release_source(NvDsSrcParentBin*, int) ()
#26 0x0000559350e1f295 in event_thread_func_2(void*) ()
#27 0x00007fdf38e75e23 in ?? () from target:/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#28 0x00007fdf38e753a5 in g_main_context_dispatch () from target:/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#29 0x00007fdf38e75770 in ?? () from target:/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#30 0x00007fdf38e75a82 in g_main_loop_run () from target:/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0
#31 0x0000559350e21e92 in main ()

I got a reply from Gstreamer.They say it breaks while deactivating NVidia specific decoder in libgstnvvideo4linux2.so.

We will have intenal team to reviw to give some updates. Thanks

Thanks,I can provide complete communication with GStreamer.
gst_element_set_state (ELEm, GST_STATE_NULL) causes a deadlock (#1065) · Issues · GStreamer / gstreamer · GitLab

One more message,destroy_pipeline function also has a chance to trigger a deadlock.

Please provide your complete code, configurations and steps of reproducing the deadlock.

source.zip (522.4 KB)
I uploaded the code and removed the classified part.
If the compilation fails, you can delete the failed code.
This part of the code is based on destroy_pipeline and create_ pipeline function to complete the operation of dynamically deleting the stream.
command:
./deepstream-test5-app -c configs/test5_config_file_src_infer.txt