Bug 1543898 - SharedWorker must release the MessagePortIdentifier if the creation fails, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 12 Apr 2019 08:02:29 +0000
changeset 469232 010b72a5a21cf34c77ad23d4a3c3ed944622b54e
parent 469231 b5f523e6d49841c25d7423870fa6e36e026e24a0
child 469233 fdd9adb9382f3af6e08d2c5f5624de9bc98bd721
push id112776
push usershindli@mozilla.com
push dateFri, 12 Apr 2019 16:20:17 +0000
treeherdermozilla-inbound@b4501ced5619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1543898
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1543898 - SharedWorker must release the MessagePortIdentifier if the creation fails, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D27230
dom/workers/sharedworkers/SharedWorkerService.cpp
--- a/dom/workers/sharedworkers/SharedWorkerService.cpp
+++ b/dom/workers/sharedworkers/SharedWorkerService.cpp
@@ -213,16 +213,20 @@ void SharedWorkerService::GetOrCreateWor
 void SharedWorkerService::GetOrCreateWorkerManagerOnMainThread(
     nsIEventTarget* aBackgroundEventTarget, SharedWorkerParent* aActor,
     const RemoteWorkerData& aData, uint64_t aWindowID,
     const MessagePortIdentifier& aPortIdentifier) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aBackgroundEventTarget);
   MOZ_ASSERT(aActor);
 
+  auto closeMessagePortIdentifier = MakeScopeExit([&] {
+    MessagePort::ForceClose(aPortIdentifier);
+  });
+
   nsresult rv = NS_OK;
   nsCOMPtr<nsIPrincipal> principal =
       PrincipalInfoToPrincipal(aData.principalInfo(), &rv);
   if (NS_WARN_IF(!principal)) {
     ErrorPropagationOnMainThread(aBackgroundEventTarget, aActor, rv);
     return;
   }
 
@@ -279,16 +283,18 @@ void SharedWorkerService::GetOrCreateWor
   }
 
   RefPtr<SharedWorkerManagerWrapper> wrapper =
       new SharedWorkerManagerWrapper(managerHolder.forget());
 
   RefPtr<WorkerManagerCreatedRunnable> r = new WorkerManagerCreatedRunnable(
       wrapper.forget(), aActor, aData, aWindowID, aPortIdentifier);
   aBackgroundEventTarget->Dispatch(r.forget(), NS_DISPATCH_NORMAL);
+
+  closeMessagePortIdentifier.release();
 }
 
 void SharedWorkerService::ErrorPropagationOnMainThread(
     nsIEventTarget* aBackgroundEventTarget, SharedWorkerParent* aActor,
     nsresult aError) {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aBackgroundEventTarget);
   MOZ_ASSERT(aActor);