Bug 1424300 P1 Gracefully handle when the service worker script cache exists, but is empty. r=edenchuang a=gchang
authorBen Kelly <ben@wanderview.com>
Thu, 14 Dec 2017 13:27:11 -0500
changeset 445355 c200bc68074adcc07f4a6ea4c5e825cfd103d0af
parent 445354 53df9fbc528e56deb67566e7e02f4441291cfd77
child 445356 a4c977f0603bb528c01f1d08a41f3641a65197d3
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersedenchuang, gchang
bugs1424300
milestone58.0
Bug 1424300 P1 Gracefully handle when the service worker script cache exists, but is empty. r=edenchuang a=gchang
dom/workers/ServiceWorkerScriptCache.cpp
--- a/dom/workers/ServiceWorkerScriptCache.cpp
+++ b/dom/workers/ServiceWorkerScriptCache.cpp
@@ -463,33 +463,48 @@ private:
       return;
     }
 
     // Fetch and compare the source scripts.
     MOZ_ASSERT(mPendingCount == 0);
 
     mState = WaitingForScriptOrComparisonResult;
 
+    // Always make sure to fetch the main script.  If the old cache has
+    // no entries or the main script entry is missing, then the loop below
+    // may not trigger it.  This should not really happen, but we handle it
+    // gracefully if it does occur.  Its possible the bad cache state is due
+    // to a crash or shutdown during an update, etc.
+    rv = FetchScript(mURL, true /* aIsMainScript */, mOldCache);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+      return;
+    }
+
     for (uint32_t i = 0; i < len; ++i) {
       JS::Rooted<JS::Value> val(aCx);
       if (NS_WARN_IF(!JS_GetElement(aCx, obj, i, &val)) ||
           NS_WARN_IF(!val.isObject())) {
         return;
       }
 
       Request* request;
       JS::Rooted<JSObject*> requestObj(aCx, &val.toObject());
       if (NS_WARN_IF(NS_FAILED(UNWRAP_OBJECT(Request, &requestObj, request)))) {
         return;
       };
 
       nsString URL;
       request->GetUrl(URL);
 
-      rv = FetchScript(URL, mURL == URL /* aIsMainScript */, mOldCache);
+      // We explicitly start the fetch for the main script above.
+      if (mURL == URL) {
+        continue;
+      }
+
+      rv = FetchScript(URL, false /* aIsMainScript */, mOldCache);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return;
       }
     }
 
     guard.release();
   }