Bug 1540913 - Part 2: Clear and shutdown ModuleLoader at worker termination; r=asuth,jonco

When running an infinitely-looping dynamic import, it is possible for the module loader to still be
holding on to that module at shutdown. Shutdown on the worker means that we will no longer run the
event loop, which will execute the dynamic import promises necessary to clear the global. The result
is that the global is kept alive. By calling `Shutdown()` we prevent this partially. We additionally
need to address the failure in the module code (next patch).

Differential Revision: https://phabricator.services.mozilla.com/D171683
This commit is contained in:
Yulia 2023-03-14 18:16:31 +00:00
parent 4e6402f008
commit 5231b910c8
4 changed files with 22 additions and 0 deletions

View File

@ -2046,6 +2046,8 @@ WorkerThreadPrimaryRunnable::Run() {
MOZ_ASSERT(!JS_IsExceptionPending(cx));
}
mWorkerPrivate->ShutdownModuleLoader();
mWorkerPrivate->RunShutdownTasks();
BackgroundChild::CloseForCurrentThread();

View File

@ -3899,6 +3899,23 @@ WorkerPrivate::ProcessAllControlRunnablesLocked() {
return result;
}
void WorkerPrivate::ShutdownModuleLoader() {
AssertIsOnWorkerThread();
WorkerGlobalScope* globalScope = GlobalScope();
if (globalScope) {
if (globalScope->GetModuleLoader(nullptr)) {
globalScope->GetModuleLoader(nullptr)->Shutdown();
}
}
WorkerDebuggerGlobalScope* debugGlobalScope = DebuggerGlobalScope();
if (debugGlobalScope) {
if (debugGlobalScope->GetModuleLoader(nullptr)) {
debugGlobalScope->GetModuleLoader(nullptr)->Shutdown();
}
}
}
void WorkerPrivate::ClearMainEventQueue(WorkerRanOrNot aRanOrNot) {
AssertIsOnWorkerThread();

View File

@ -456,6 +456,8 @@ class WorkerPrivate final
return mCancelAllPendingRunnables;
}
void ShutdownModuleLoader();
void ClearMainEventQueue(WorkerRanOrNot aRanOrNot);
void ClearDebuggerEventQueue();

View File

@ -993,6 +993,7 @@ ModuleLoaderBase::~ModuleLoaderBase() {
}
void ModuleLoaderBase::Shutdown() {
CancelAndClearDynamicImports();
MOZ_ASSERT(mFetchingModules.IsEmpty());
for (const auto& entry : mFetchedModules) {