Bug 1680310 - Gracefully handle functions running after we Shutdown in RemoteDecoderManagerChild. r=jya

RemoteDecoderManagerChild has a number of functions that may be called
asynchronously. Many such functions assert that they can get the manager thread
and that they are on that thread. However, if we've already shutdown, the thread
they fetch will be null. Since we can enter shutdown while async executions of
these functions are pending, we may fail our asserts.

To avoid this, we instead check if the manager thread is null in these
functions, if so, we assume we're in shutdown and bail. If the thread is not
null, we continue as before and assert we are running on the thread as expected.

Differential Revision: https://phabricator.services.mozilla.com/D99824
This commit is contained in:
Bryce Seager van Dyk 2020-12-21 15:03:01 +00:00
Родитель 1044e8fc9e
Коммит 0f3a7c7723
1 изменённых файлов: 25 добавлений и 4 удалений

Просмотреть файл

@ -144,7 +144,12 @@ void RemoteDecoderManagerChild::Shutdown() {
void RemoteDecoderManagerChild::RunWhenGPUProcessRecreated(
already_AddRefed<Runnable> aTask) {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
nsCOMPtr<nsISerialEventTarget> managerThread = GetManagerThread();
if (!managerThread) {
// We've been shutdown, bail.
return;
}
MOZ_ASSERT(managerThread->IsOnCurrentThread());
// If we've already been recreated, then run the task immediately.
auto* manager = GetSingleton(RemoteDecodeIn::GpuProcess);
@ -159,7 +164,12 @@ void RemoteDecoderManagerChild::RunWhenGPUProcessRecreated(
/* static */
RemoteDecoderManagerChild* RemoteDecoderManagerChild::GetSingleton(
RemoteDecodeIn aLocation) {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
nsCOMPtr<nsISerialEventTarget> managerThread = GetManagerThread();
if (!managerThread) {
// We've been shutdown, bail.
return nullptr;
}
MOZ_ASSERT(managerThread->IsOnCurrentThread());
switch (aLocation) {
case RemoteDecodeIn::GpuProcess:
return sRemoteDecoderManagerChildForGPUProcess;
@ -405,7 +415,13 @@ RemoteDecoderManagerChild::RemoteDecoderManagerChild(RemoteDecodeIn aLocation)
void RemoteDecoderManagerChild::OpenForRDDProcess(
Endpoint<PRemoteDecoderManagerChild>&& aEndpoint) {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
nsCOMPtr<nsISerialEventTarget> managerThread = GetManagerThread();
if (!managerThread) {
// We've been shutdown, bail.
return;
}
MOZ_ASSERT(managerThread->IsOnCurrentThread());
// Only create RemoteDecoderManagerChild, bind new endpoint and init
// ipdl if:
// 1) haven't init'd sRemoteDecoderManagerChild
@ -429,7 +445,12 @@ void RemoteDecoderManagerChild::OpenForRDDProcess(
void RemoteDecoderManagerChild::OpenForGPUProcess(
Endpoint<PRemoteDecoderManagerChild>&& aEndpoint) {
MOZ_ASSERT(GetManagerThread() && GetManagerThread()->IsOnCurrentThread());
nsCOMPtr<nsISerialEventTarget> managerThread = GetManagerThread();
if (!managerThread) {
// We've been shutdown, bail.
return;
}
MOZ_ASSERT(managerThread->IsOnCurrentThread());
// Make sure we always dispatch everything in sRecreateTasks, even if we
// fail since this is as close to being recreated as we will ever be.
sRemoteDecoderManagerChildForGPUProcess = nullptr;