After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 548764 - New basetransform doesn't lock pad properly when looking at its caps
New basetransform doesn't lock pad properly when looking at its caps
Status: RESOLVED NOTABUG
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Linux
: Normal critical
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-08-20 22:57 UTC by Olivier Crête
Modified: 2008-09-29 19:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Lock the pad before looking at its internal stuff (2.51 KB, patch)
2008-08-20 22:58 UTC, Olivier Crête
none Details | Review
Check for NULL caps and also unref them (4.54 KB, patch)
2008-08-20 23:50 UTC, Olivier Crête
none Details | Review
Example of stack trace from crash (32.83 KB, text/plain)
2008-09-10 17:07 UTC, Olivier Crête
  Details

Description Olivier Crête 2008-08-20 22:57:37 UTC
The new basetransform stuff doesn't lock the pad properly, in the right conditions, it causes a race where it sets the old caps on a buffer, not the new ones.

I'm attaching a patch that just locks the pad before using the caps, but should it not instead use gst_pad_get_negotiated_caps() ?
Comment 1 Olivier Crête 2008-08-20 22:58:28 UTC
Created attachment 117091 [details] [review]
Lock the pad before looking at its internal stuff
Comment 2 Olivier Crête 2008-08-20 23:50:46 UTC
Created attachment 117094 [details] [review]
Check for NULL caps and also unref them

Improved patch that doesnt leak them and checks for the null-ness.. Would be simple if we used gst_pad_get_negotiated_caps().. but is it appriopriate?
Comment 3 Wim Taymans 2008-08-21 09:29:23 UTC
When exactly can it go wrong? Do you have a testcase or seen it fail? 

I can only see it fail if someone in the subclass calls a setcaps() on a pad. Normally the caps are protected with the STREAM_LOCK or OBJECT lock on the pads, the code you change is usually called in the STREAM_LOCK.
Comment 4 Tim-Philipp Müller 2008-09-10 13:39:37 UTC
Ping? Should this be a blocker for the upcoming release? (Marking it as such for now)

What did you see fail exactly? Do you have a test case for the problem you've run into? Can we easily reproduce it somehow?
Comment 5 Olivier Crête 2008-09-10 17:07:01 UTC
Created attachment 118442 [details]
Example of stack trace from crash
Comment 6 Olivier Crête 2008-09-10 17:14:37 UTC
Yes, it should really be a blocker.

Sadly, I don't have a "simple" test case. The test case involves running all of farsight2.

To reproduce:
get farsight2 0.0.3 (or the git trunk) and build it

cd tests/gui
G_DEBUG=fatal-warnings python fs2-gui.py
click "New Server"
in another term, do the same thing.. but click "Connect" to connect to the server
Watch video being transfered between both sides.
Try changing the video codec on one side or on the other side..
Enjoy crash.

The way I see it is quite simple.. Either GST_PAD_CAPS() is protected by the stream lock or by the object lock. If its the stream lock .. the GstPad should be fixed, if its the object lock, the basetransform should be fixed.
Comment 7 Olivier Crête 2008-09-10 17:16:36 UTC
I forgot one thing..  You may need the patches from bug #530935 too.
Comment 8 Jan Schmidt 2008-09-23 18:10:30 UTC
What's happening with this bug - we need to get it fixed for the release.
Comment 9 Wim Taymans 2008-09-24 13:24:31 UTC
What element is after the h264 payloader?
Comment 10 Olivier Crête 2008-09-24 14:24:20 UTC
(In reply to comment #9)
> What element is after the h264 payloader?

capsfilter->dtmfrtpmux->gsrtpbin->tee->udpsink more or less
Comment 11 Wim Taymans 2008-09-24 14:49:23 UTC
ok, this is what is obviously wrong in the case of capfilter:

 - basetransform does outcaps = GST_PAD_CAPS (trans->srcpad)
 - basetransform calls ->prepare_output_buffer (..., outcaps ,..)
 - capsfilter does gst_pad_set_caps (trans->srcpad, newcaps) affectively
   decreasing the refcount we had on outcaps
 - basetransform continues using outcaps eventhough it might have lost the ref
   by calling ->prepare_output_buffer.

I'll start by applying the patch for this case.
Comment 12 Wim Taymans 2008-09-24 15:04:09 UTC
Can you retest to see if the caps mayhem was cause by this:

        * libs/gst/base/gstbasetransform.c:
        (gst_base_transform_prepare_output_buffer):
        Take new caps ref because our old one might have been gone when the
        subclass performs a gst_pad_set_caps() on the srcpad. See #548764.
Comment 13 Wim Taymans 2008-09-25 17:25:47 UTC
Adding refs and locks now and lowering priority.

        Patch by: Olivier Crete <tester at tester dot ca>

        * libs/gst/base/gstbasetransform.c:
        (gst_base_transform_prepare_output_buffer),
        (gst_base_transform_activate):
        Temporary fix for blocker bug #548764. Take more caps refs and take the 
        pad lock while doing so. This problem is likely caused by some
        refcounting problem elsewhere but we don't know where yet.
Comment 14 Wim Taymans 2008-09-29 19:18:51 UTC
I refrained from committing the patch I talked about in Comment #13 because I did not understand why it would be needed. 

Some more debugging revealed a caps refcount error in some other plugin. Then error seems fixed now, closing.