Bug 183483

Summary: RealtimeOutgoingAudioSource and RealtimeOutgoingVideoSource should be destroyed on the main thread
Product: WebKit Reporter: youenn fablet <youennf>
Component: WebRTCAssignee: youenn fablet <youennf>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, commit-queue, eric.carlson, ews-watchlist, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch for landing none

Description youenn fablet 2018-03-08 14:50:28 PST
RealtimeOutgoingAudioSource and RealtimeOutgoingVideoSource should be destroyed on the main thread
Comment 1 youenn fablet 2018-03-08 14:51:38 PST
<rdar://problem/38214152>
Comment 2 youenn fablet 2018-03-08 15:44:05 PST
Created attachment 335358 [details]
Patch
Comment 3 EWS Watchlist 2018-03-08 15:46:43 PST
Attachment 335358 [details] did not pass style-queue:


ERROR: Source/WebCore/platform/mediastream/RealtimeOutgoingVideoSource.h:39:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 8 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 youenn fablet 2018-03-08 15:49:14 PST
Created attachment 335359 [details]
Patch
Comment 5 Chris Dumez 2018-03-08 16:56:05 PST
Comment on attachment 335359 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=335359&action=review

> Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp:79
> +    RefPtr<Thread> m_thread;

Is this OK? Are we sure this does not create a cycle?

> Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp:84
> +    // Free senders in a different thread like could be done with actual peer connection.

So we can just free senders on any thread but not the current one?

> Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp:86
> +    auto threadFunction =  [this, keeper = keeper.copyRef(), senders = WTFMove(m_senders)] { };

Why is this capture this? Any use of this would likely crash.
Comment 6 youenn fablet 2018-03-08 17:16:53 PST
Comment on attachment 335359 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=335359&action=review

>> Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp:79
>> +    RefPtr<Thread> m_thread;
> 
> Is this OK? Are we sure this does not create a cycle?

It should not create a cycle, since the thread entry function is deleted after being called.
That said, looking at it further, there is probably no need for ThreadKeeper at all.

>> Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp:84
>> +    // Free senders in a different thread like could be done with actual peer connection.
> 
> So we can just free senders on any thread but not the current one?

Since it is a mock, this would always be freed in the main thread.
And we want to test the case of sources being derefed in a non main thread.

>> Source/WebCore/testing/MockLibWebRTCPeerConnection.cpp:86
>> +    auto threadFunction =  [this, keeper = keeper.copyRef(), senders = WTFMove(m_senders)] { };
> 
> Why is this capture this? Any use of this would likely crash.

Not needed indeed.
Comment 7 youenn fablet 2018-03-09 08:55:20 PST
Created attachment 335427 [details]
Patch
Comment 8 Eric Carlson 2018-03-09 09:33:21 PST
Comment on attachment 335427 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=335427&action=review

> Source/WebCore/testing/MockLibWebRTCPeerConnection.h:217
> +    bool SetTrack(webrtc::MediaStreamTrackInterface* track) final
> +    {
> +        m_track = track;
> +        return true;
> +    }

Is this related? A note in the ChangeLog about why this was changed would be helpful.
Comment 9 youenn fablet 2018-03-09 09:58:10 PST
Created attachment 335432 [details]
Patch for landing
Comment 10 youenn fablet 2018-03-09 10:05:09 PST
(In reply to Eric Carlson from comment #8)
> Comment on attachment 335427 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=335427&action=review
> 
> > Source/WebCore/testing/MockLibWebRTCPeerConnection.h:217
> > +    bool SetTrack(webrtc::MediaStreamTrackInterface* track) final
> > +    {
> > +        m_track = track;
> > +        return true;
> > +    }
> 
> Is this related? A note in the ChangeLog about why this was changed would be
> helpful.

Thanks for the review.
The track change ensures that we keep a reference if we use SetTrack so that it can be freed later on a wrong thread. This is not strictly needed but might help in the future.
Comment 11 WebKit Commit Bot 2018-03-09 16:38:07 PST
Comment on attachment 335432 [details]
Patch for landing

Clearing flags on attachment: 335432

Committed r229491: <https://trac.webkit.org/changeset/229491>
Comment 12 WebKit Commit Bot 2018-03-09 16:38:08 PST
All reviewed patches have been landed.  Closing bug.