Bug 173739 - LibWebRTCSocketClient should not destroy its socket within signalClose callback
Summary: LibWebRTCSocketClient should not destroy its socket within signalClose callback
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-06-22 15:16 PDT by youenn fablet
Modified: 2017-06-23 13:43 PDT (History)
6 users (show)

See Also:


Attachments
Patch (1.86 KB, patch)
2017-06-22 15:23 PDT, 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 2017-06-22 15:16:03 PDT
LibWebRTCSocketClient should not destroy its socket within signalClose callback
Comment 1 youenn fablet 2017-06-22 15:16:17 PDT
rdar://problem/32922877
Comment 2 youenn fablet 2017-06-22 15:23:45 PDT
Created attachment 313666 [details]
Patch
Comment 3 Brent Fulgham 2017-06-23 09:21:32 PDT
Comment on attachment 313666 [details]
Patch

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

> Source/WebKit2/NetworkProcess/webrtc/LibWebRTCSocketClient.cpp:141
> +    m_rtcProvider.callOnRTCNetworkThread([socket = m_rtcProvider.takeSocket(m_identifier)] { });

How do we know this is sufficient lifespan? I don't think that anything really guarantees that the RTCNetworkThread doesn't wake up and do the destruction before the caller of LibWebRTCSocketClient::signalClose() has a chance to finish using the socket. It seems like the caller needs some way to keep 'socket' alive for as long as it needs to use it.
Comment 4 Brent Fulgham 2017-06-23 09:24:29 PDT
Comment on attachment 313666 [details]
Patch

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

r=me

>> Source/WebKit2/NetworkProcess/webrtc/LibWebRTCSocketClient.cpp:141
>> +    m_rtcProvider.callOnRTCNetworkThread([socket = m_rtcProvider.takeSocket(m_identifier)] { });
> 
> How do we know this is sufficient lifespan? I don't think that anything really guarantees that the RTCNetworkThread doesn't wake up and do the destruction before the caller of LibWebRTCSocketClient::signalClose() has a chance to finish using the socket. It seems like the caller needs some way to keep 'socket' alive for as long as it needs to use it.

Looking further, I guess the only caller of LibWebRTCSocketClient::signalClose is the WebRTCSocket message handler, which calls this method and doesn't do anything else.

We might have a number of queued up messages to be handled that need socket, but by putting the destruction in the message queue, we guarantee that those tasks are done by the time we are allowed to destroy the socket.

So I'm confident this change is correct.
Comment 5 youenn fablet 2017-06-23 09:45:48 PDT
(In reply to Brent Fulgham from comment #4)
> Comment on attachment 313666 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=313666&action=review
> 
> r=me
> 
> >> Source/WebKit2/NetworkProcess/webrtc/LibWebRTCSocketClient.cpp:141
> >> +    m_rtcProvider.callOnRTCNetworkThread([socket = m_rtcProvider.takeSocket(m_identifier)] { });
> > 
> > How do we know this is sufficient lifespan? I don't think that anything really guarantees that the RTCNetworkThread doesn't wake up and do the destruction before the caller of LibWebRTCSocketClient::signalClose() has a chance to finish using the socket. It seems like the caller needs some way to keep 'socket' alive for as long as it needs to use it.
> 
> Looking further, I guess the only caller of
> LibWebRTCSocketClient::signalClose is the WebRTCSocket message handler,
> which calls this method and doesn't do anything else.
> 
> We might have a number of queued up messages to be handled that need socket,
> but by putting the destruction in the message queue, we guarantee that those
> tasks are done by the time we are allowed to destroy the socket.
> 
> So I'm confident this change is correct.

Right, maybe I should beef up the change log?
Comment 6 WebKit Commit Bot 2017-06-23 13:43:45 PDT
Comment on attachment 313666 [details]
Patch

Clearing flags on attachment: 313666

Committed r218759: <http://trac.webkit.org/changeset/218759>
Comment 7 WebKit Commit Bot 2017-06-23 13:43:46 PDT
All reviewed patches have been landed.  Closing bug.