Bug 222293 - [GPUP] Use a WeakPtr of GPUConnectionToWebProcess instead of a reference in some media related objects
Summary: [GPUP] Use a WeakPtr of GPUConnectionToWebProcess instead of a reference in s...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Peng Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-02-22 15:59 PST by Peng Liu
Modified: 2021-02-24 22:45 PST (History)
7 users (show)

See Also:


Attachments
Patch (72.85 KB, patch)
2021-02-22 16:10 PST, Peng Liu
eric.carlson: review+
Details | Formatted Diff | Diff
Revise the patch based on Eric's comments (79.50 KB, patch)
2021-02-24 15:13 PST, Peng Liu
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peng Liu 2021-02-22 15:59:46 PST
[GPUP] Use a WeakPtr of GPUConnectionToWebProcess instead of a reference in some media related objects
Comment 1 Peng Liu 2021-02-22 16:09:52 PST
<rdar://74560577>
Comment 2 Peng Liu 2021-02-22 16:10:34 PST
Created attachment 421258 [details]
Patch
Comment 3 Eric Carlson 2021-02-23 11:10:55 PST
Comment on attachment 421258 [details]
Patch

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

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp:204
>  const Logger& RemoteMediaPlayerManagerProxy::logger() const
>  {
> -    return m_gpuConnectionToWebProcess.logger();
> +    ASSERT(m_gpuConnectionToWebProcess);
> +    return m_gpuConnectionToWebProcess->logger();
>  }

This won't go well if the connection to the web process goes away. 

You should probably change it to `RemoteMediaPlayerManagerProxy::loggerPtr()`, and change the log sites that called this to use `*_LOG_IF(loggerPtr(), ...`

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:140
> +    ASSERT(m_manager.gpuConnectionToWebProcess());
> +    m_mediaSourceProxy = adoptRef(*new RemoteMediaSourceProxy(*m_manager.gpuConnectionToWebProcess(), mediaSourceIdentifier, webMParserEnabled, *this));

This will crash in a release build, so you should rearrange the code so you can return a configuration that signals an error if the web process is gone.

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:255
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

This will also crash and needs to be restructured.

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:381
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto.

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:415
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:486
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:508
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:530
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:622
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:820
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:851
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:859
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:867
> +    ASSERT(m_manager.gpuConnectionToWebProcess());

Ditto

> Source/WebKit/GPUProcess/media/RemoteMediaSourceProxy.cpp:55
> +    ASSERT(m_connectionToWebProcess);

Ditto

> Source/WebKit/GPUProcess/media/RemoteSourceBufferProxy.cpp:63
> +    m_connectionToWebProcess->messageReceiverMap().removeMessageReceiver(Messages::RemoteSourceBufferProxy::messageReceiverName(), m_identifier.toUInt64());

Ditto
Comment 4 Peng Liu 2021-02-24 14:08:07 PST
Comment on attachment 421258 [details]
Patch

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

>> Source/WebKit/GPUProcess/media/RemoteMediaPlayerManagerProxy.cpp:204
>>  }
> 
> This won't go well if the connection to the web process goes away. 
> 
> You should probably change it to `RemoteMediaPlayerManagerProxy::loggerPtr()`, and change the log sites that called this to use `*_LOG_IF(loggerPtr(), ...`

Based on a discussion with Eric, I changed the implementation to create a logger in RemoteMediaPlayerManagerProxy instead of using the logger created by GPUConnectionToWebProcess.

>> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:140
>> +    m_mediaSourceProxy = adoptRef(*new RemoteMediaSourceProxy(*m_manager.gpuConnectionToWebProcess(), mediaSourceIdentifier, webMParserEnabled, *this));
> 
> This will crash in a release build, so you should rearrange the code so you can return a configuration that signals an error if the web process is gone.

Right. In addition, we will need to check whether "m_manager" is destroyed or not. Because m_manager (RemoteMediaPlayerManagerProxy) is owned by GPUConnectionToWebProcess. When the GPUConnectionToWebProcess instance is destroyed, the "m_manager" will be destroyed as well.

We have to keep a WeakPtr of RemoteMediaPlayerManagerProxy in RemoteMediaPlayerProxy to implement that.

>> Source/WebKit/GPUProcess/media/RemoteMediaPlayerProxy.cpp:255
>> +    ASSERT(m_manager.gpuConnectionToWebProcess());
> 
> This will also crash and needs to be restructured.

Right. Fixed as described by the above comment.
And the same for following comments.
Comment 5 Peng Liu 2021-02-24 15:13:36 PST
Created attachment 421465 [details]
Revise the patch based on Eric's comments
Comment 6 EWS 2021-02-24 22:31:13 PST
commit-queue failed to commit attachment 421465 [details] to WebKit repository. To retry, please set cq+ flag again.
Comment 7 EWS 2021-02-24 22:45:32 PST
Committed r273473: <https://commits.webkit.org/r273473>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 421465 [details].