<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>214073</bug_id>
          
          <creation_ts>2020-07-08 01:33:55 -0700</creation_ts>
          <short_desc>[MediaStream][GStreamer] MediaStreamTrackPrivate unref&apos;ed from streaming thread</short_desc>
          <delta_ts>2020-07-08 04:06:10 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKitGTK</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>214047</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alicia Boya García">aboya</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bugs-noreply</cc>
    
    <cc>pnormand</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1669691</commentid>
    <comment_count>0</comment_count>
    <who name="Alicia Boya García">aboya</who>
    <bug_when>2020-07-08 01:33:55 -0700</bug_when>
    <thetext>This is the code:

struct ProbeData {
    WTF_MAKE_STRUCT_FAST_ALLOCATED;
    ProbeData(GstElement* element, GstStaticPadTemplate* padTemplate, RefPtr&lt;MediaStreamTrackPrivate&gt; track)
        : element(element)
        , padTemplate(padTemplate)
        , track(track) { }

    GRefPtr&lt;GstElement&gt; element;
    GstStaticPadTemplate* padTemplate;
    RefPtr&lt;MediaStreamTrackPrivate&gt; track;
};

[...]

        gst_pad_add_probe(pad.get(), GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM, reinterpret_cast&lt;GstPadProbeCallback&gt;(webkitMediaStreamSrcPadProbeCb), data, [](gpointer data) {
            delete reinterpret_cast&lt;ProbeData*&gt;(data);
        });

MediaStreamTrackPrivate is not ThreadSafeRefCounted, so it is not safe to unref from non-main thread.

If MediaStreamTrackPrivate is guaranteed to be alive by the time the probe runs, use a plain old pointer instead of RefPtr for MediaStreamTrackPrivate. Otherwise, if holding a reference inside the probe (which will run in the streaming thread) is desirable, make MediaStreamTrackPrivate inherit from ThreadSafeRefCounted.

STDERR: ASSERTION FAILED: Unsafe to ref/deref from different threadsASSERTION FAILED: Unsafe to ref/deref from different threads
STDERR: m_isOwnedByMainThread == isMainThread()

Thread 1 (Thread 0x7f43318fe700 (LWP 640)):
#0  0x00007f438b7bdfc2 in WTFCrash() () at ../../Source/WTF/wtf/Assertions.cpp:295
#1  0x00007f4399b41453 in WTF::RefCountedBase::applyRefDerefThreadingCheck() const (this=0x7f433073ec48) at DerivedSources/ForwardingHeaders/wtf/RefCounted.h:114
#2  0x00007f4399b414f0 in WTF::RefCountedBase::derefBase() const (this=0x7f433073ec48) at DerivedSources/ForwardingHeaders/wtf/RefCounted.h:130
#3  0x00007f439b2738a5 in WTF::RefCounted&lt;WebCore::MediaStreamTrackPrivate, std::default_delete&lt;WebCore::MediaStreamTrackPrivate&gt; &gt;::deref() const (this=0x7f433073ec48) at DerivedSources/ForwardingHeaders/wtf/RefCounted.h:189
#4  0x00007f439b273290 in WTF::derefIfNotNull&lt;WebCore::MediaStreamTrackPrivate&gt;(WebCore::MediaStreamTrackPrivate*) (ptr=0x7f433073ec30) at DerivedSources/ForwardingHeaders/wtf/RefPtr.h:44
#5  0x00007f439b2726ce in WTF::RefPtr&lt;WebCore::MediaStreamTrackPrivate, WTF::DumbPtrTraits&lt;WebCore::MediaStreamTrackPrivate&gt; &gt;::~RefPtr() (this=0x7f433074e118, __in_chrg=&lt;optimized out&gt;) at DerivedSources/ForwardingHeaders/wtf/RefPtr.h:70
#6  0x00007f439b272118 in ProbeData::~ProbeData() (this=0x7f433074e108, __in_chrg=&lt;optimized out&gt;) at ../../Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp:450
#7  0x00007f439b26f8a6 in &lt;lambda(gpointer)&gt;::operator()(gpointer) const (__closure=0x0, data=0x7f433074e108) at ../../Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp:500
#8  0x00007f439b26f8d3 in &lt;lambda(gpointer)&gt;::_FUN(gpointer) () at ../../Source/WebCore/platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp:501
#9  0x00007f4384ba1f7d in g_hook_free (hook_list=0x5634ab9565e8, hook=0x5634ab5d3240) at ../glib/ghook.c:302
#10 0x00007f4384ba2486 in g_hook_next_valid (hook_list=&lt;optimized out&gt;, hook=&lt;optimized out&gt;, may_be_in_call=&lt;optimized out&gt;) at ../glib/ghook.c:757
#11 0x00007f4384ba28ae in g_hook_list_marshal (hook_list=hook_list@entry=0x5634ab9565e8, may_recurse=may_recurse@entry=1, marshaller=marshaller@entry=0x7f43854d2440 &lt;probe_hook_marshal&gt;, data=data@entry=0x7f43318fd800) at ../glib/ghook.c:676
#12 0x00007f43854d1ede in do_probe_callbacks (pad=pad@entry=0x5634ab956550 [GstPad|src], info=&lt;optimized out&gt;, defaultval=defaultval@entry=GST_FLOW_OK) at ../gst/gstpad.c:3728
#13 0x00007f43854d5617 in gst_pad_push_event_unchecked (pad=pad@entry=0x5634ab956550 [GstPad|src], event=0x7f4320007df0 [GstEvent], type=type@entry=GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM) at ../gst/gstpad.c:5376
#14 0x00007f43854d5bca in push_sticky (pad=pad@entry=0x5634ab956550 [GstPad|src], ev=ev@entry=0x7f43318fda10, user_data=user_data@entry=0x7f43318fda80) at ../gst/gstevent.h:438
#15 0x00007f43854d3520 in events_foreach (pad=pad@entry=0x5634ab956550 [GstPad|src], func=func@entry=0x7f43854d5b70 &lt;push_sticky&gt;, user_data=user_data@entry=0x7f43318fda80) at ../gst/gstpad.c:608
#16 0x00007f43854de491 in check_sticky (event=0x7f4320007df0 [GstEvent], pad=0x5634ab956550 [GstPad|src]) at ../gst/gstpad.c:3986
#17 0x00007f43854de491 in gst_pad_push_event (pad=0x5634ab956550 [GstPad|src], event=event@entry=0x7f4320007df0 [GstEvent]) at ../gst/gstpad.c:5542
#18 0x00007f43855d8a38 in gst_base_src_send_stream_start (src=src@entry=0x5634ab17b610 [GstAppSrc|appsrc1]) at ../libs/gst/base/gstbasesrc.c:916
#19 0x00007f43855d92e8 in gst_base_src_send_stream_start (src=0x5634ab17b610 [GstAppSrc|appsrc1]) at ../libs/gst/base/gstbasesrc.c:3401
#20 0x00007f43855d92e8 in gst_base_src_loop (pad=0x5634ab956550 [GstPad|src]) at ../libs/gst/base/gstbasesrc.c:2797
#21 0x00007f438550bbe7 in gst_task_func (task=0x5634ab586a70 [GstTask|appsrc1:src]) at ../gst/gsttask.c:328
#22 0x00007f4384bdd004 in g_thread_pool_thread_proxy (data=&lt;optimized out&gt;) at ../glib/gthreadpool.c:354
#23 0x00007f4384bdc761 in g_thread_proxy (data=0x5634ab42cb60) at ../glib/gthread.c:807
#24 0x00007f4385c305e2 in start_thread (arg=&lt;optimized out&gt;) at pthread_create.c:479
#25 0x00007f43838c0473 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1669714</commentid>
    <comment_count>1</comment_count>
    <who name="Philippe Normand">pnormand</who>
    <bug_when>2020-07-08 04:06:10 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 214047 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>