GNOME Bugzilla – Bug 574293
[decodebin2] deadlock on shutdown
Last modified: 2009-03-09 12:37:24 UTC
Consider a decodebin2 (e.g. in playbin2 pipeline) that is set to PAUSED, and (about) immediately upon return from set_state set to READY, then a race occurs between the (mainloop) thread trying to shutdown to READY, and streaming thread callbacks building the bin, which may result in a deadlock. Specifically, consider decodebin2 plugging a typical demuxer that exposes 1 video and 1 audio pad. Streaming thread(s) plug more elements, set up a decodegroup, decodepads, and pad blocks on (unexposed) ghostpads. Consider streaming has reached the stage where 1 pad has blocked. At this point, the mainloop (performing a shutdown to READY) sets the most downstream element whose corresponding src pad has not yet blocked to READY. Then it sets the other most downstream element to READY, and tries to grab the STREAM_LOCK. This blocks, as this thread in question is in a pad block. Since the other downstream element is now flushing, the other ghostpad will never block, so the decodegroup will not be exposed (part of which unblocks the pads). Since the blocked pads are ghostpads, core will not unblock them either as part of any element's state change.
Created attachment 130147 [details] gdb backtrace gdb backtrace illustrating the scenario described above
Created attachment 130210 [details] [review] Possible patch Unblock blocked ghostpads when shutting down. This provides a fix at "decodebin2 level" although a similar problem might occur elsewhere, since blocked ghostpads are not necessarily unblocked by core during pad deactivation. An possible (more generic) alternative might be to use GstPad(Un)BlockFunction, and to perform some proxying for proxypads/ghostpads.
My analisis of the problem was that core does indeed deactivates and flushes blocked the pads when going to READY but there is a race where the pad can be added after the bin iterated the pads, leaving the pad blocked. I think with the shutdown lock, ie not adding any pads (and setting them inactive) when the bin is shutting down, should do the trick.
commit b7ea2a9105107fe9f5130e4d0594196e52fb0e71 Author: Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk> Date: Fri Mar 6 19:28:37 2009 +0100 Unblock blocked ghostpads when shutting down. Fixes #574293.