rtspclientsink: deadlock when doing set_state(NULL)
Describe your issue
In our application we use gstreamer to show video from an rtsp camera in a Windows C# application. We'd like to allow the user to restream that video to an instance of rtsp-simple-server for easier redistribution. When trying to make the application pause the pipeline, add a branch ending in an rtspclientsink and then unpausing the pipeline, it seems the application may end up deadlocking when trying to set_state(NULL) on the elements to be removed.
Note that the deadlock doesn't always happen, and the frequency seems to perhaps be dependent on gstreamer version, with 1.20.2 being worse than 1.16.4.
Expected Behavior
set_state(NULL) on elements to be removed succeeds.
Observed Behavior
set_state(NULL) deadlocks, apparently inside the rtspclientsink.
Setup
This issue was originally seen on Windows 11 with gstreamer 1.20.1 installed with choco along with a C# application using a custom compiled gstreamer-dll for x86_64.
For easier reproduction, a Qt C++ application was built on Ubuntu Linux 20.04 using both gstreamer 1.16.4 and 1.20.2 (the latter from this PPA), and apparently the same issue affects these platforms too.
Steps to reproduce the bug
This snippet is the code I used for reproduction on Linux.
How reproducible is the bug?
On gstreamer 1.20.2 it seems to happen perhaps every second time restreaming is toggled, on 1.16.4 perhaps every 10th time.
Screenshots if relevant
Solutions you have tried
Related non-duplicate issues
Additional Information
The example above is a pretty naive application, with just minimal changes on top of samples. If there's anything I can do on the application side to handle this more robustly, I'm all ears.