Bug 183483 - RealtimeOutgoingAudioSource and RealtimeOutgoingVideoSource should be destroyed on the main thread
Summary: RealtimeOutgoingAudioSource and RealtimeOutgoingVideoSource should be destroy...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-03-08 14:50 PST by youenn fablet
Modified: 2018-03-09 16:38 PST (History)
6 users (show)

See Also:


Attachments
Patch (9.07 KB, patch)
2018-03-08 15:44 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (8.77 KB, patch)
2018-03-08 15:49 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (8.33 KB, patch)
2018-03-09 08:55 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (8.52 KB, patch)
2018-03-09 09:58 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.