Bug 1329716 Try to ensure we don't dispatch a SW event if the registration has been removed. r=asuth
authorBen Kelly <ben@wanderview.com>
Mon, 09 Jan 2017 13:40:46 -0800
changeset 373670 4097854c271e69031eab4db31cdade88f82f6c9f
parent 373669 15057def8d407c1affb92500922dfb340e36f170
child 373671 b12ad3ab9baa85165ff39daeb501e6210e88313f
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1329716
milestone53.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 1329716 Try to ensure we don't dispatch a SW event if the registration has been removed. r=asuth
dom/workers/ServiceWorkerManager.cpp
dom/workers/ServiceWorkerPrivate.cpp
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -935,16 +935,17 @@ ServiceWorkerManager::SendPushEvent(cons
 
   ServiceWorkerInfo* serviceWorker = GetActiveWorkerInfoForScope(attrs, aScope);
   if (NS_WARN_IF(!serviceWorker)) {
     return NS_ERROR_FAILURE;
   }
 
   RefPtr<ServiceWorkerRegistrationInfo> registration =
     GetRegistration(serviceWorker->GetPrincipal(), aScope);
+  MOZ_DIAGNOSTIC_ASSERT(registration);
 
   return serviceWorker->WorkerPrivate()->SendPushEvent(aMessageId, aData,
                                                        registration);
 }
 
 NS_IMETHODIMP
 ServiceWorkerManager::SendPushSubscriptionChangeEvent(const nsACString& aOriginAttributes,
                                                       const nsACString& aScope)
--- a/dom/workers/ServiceWorkerPrivate.cpp
+++ b/dom/workers/ServiceWorkerPrivate.cpp
@@ -587,17 +587,17 @@ protected:
   nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> mRegistration;
 public:
   ExtendableFunctionalEventWorkerRunnable(WorkerPrivate* aWorkerPrivate,
                                           KeepAliveToken* aKeepAliveToken,
                                           nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo>& aRegistration)
     : ExtendableEventWorkerRunnable(aWorkerPrivate, aKeepAliveToken)
     , mRegistration(aRegistration)
   {
-    MOZ_ASSERT(aRegistration);
+    MOZ_DIAGNOSTIC_ASSERT(aRegistration);
   }
 
   void
   PostRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate, bool aRunResult)
   {
     nsCOMPtr<nsIRunnable> runnable =
       new RegistrationUpdateRunnable(mRegistration, true /* time check */);
     aWorkerPrivate->DispatchToMainThread(runnable.forget());
@@ -1707,16 +1707,26 @@ ServiceWorkerPrivate::SendFetchEvent(nsI
   }
 
   RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
   MOZ_ASSERT(swm);
 
   RefPtr<ServiceWorkerRegistrationInfo> registration =
     swm->GetRegistration(mInfo->GetPrincipal(), mInfo->Scope());
 
+  // Its possible the registration is removed between starting the interception
+  // and actually dispatching the fetch event.  In these cases we simply
+  // want to restart the original network request.  Since this is a normal
+  // condition we handle the reset here instead of returning an error which
+  // would in turn trigger a console report.
+  if (!registration) {
+    aChannel->ResetInterception();
+    return NS_OK;
+  }
+
   // Handle Fetch algorithm - step 16. If the service worker didn't register
   // any fetch event handlers, then abort the interception and maybe trigger
   // the soft update algorithm.
   if (!mInfo->HandlesFetch()) {
     aChannel->ResetInterception();
 
     // Trigger soft updates if necessary.
     registration->MaybeScheduleTimeCheckAndUpdate();