Bug 1369051 - Assertion failure: !entry || !entry->IsFresh() in CacheIndex::UpdateIndex, r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Fri, 11 Aug 2017 12:30:59 +0200
changeset 374278 95536a26dee792519443940c16be95ffa87ac006
parent 374277 22734f3d4b603253f6e9ba1b4ff9bd36e4a73712
child 374279 0aca62e914cf96bae93d8fbafd4c9ce43c153116
push id32318
push userkwierso@gmail.com
push dateFri, 11 Aug 2017 20:16:01 +0000
treeherdermozilla-central@80ff3f300e05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1369051
milestone57.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 1369051 - Assertion failure: !entry || !entry->IsFresh() in CacheIndex::UpdateIndex, r=honzab
netwerk/cache2/CacheIndex.cpp
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -2801,21 +2801,26 @@ CacheIndex::BuildIndex()
 
   while (true) {
     if (CacheIOThread::YieldAndRerun()) {
       LOG(("CacheIndex::BuildIndex() - Breaking loop for higher level events."));
       mUpdateEventPending = true;
       return;
     }
 
+    bool fileExists = false;
     nsCOMPtr<nsIFile> file;
     {
       // Do not do IO under the lock.
       StaticMutexAutoUnlock unlock(sLock);
       rv = mDirEnumerator->GetNextFile(getter_AddRefs(file));
+
+      if (file) {
+        file->Exists(&fileExists);
+      }
     }
     if (mState == SHUTDOWN) {
       return;
     }
     if (!file) {
       FinishUpdate(NS_SUCCEEDED(rv));
       return;
     }
@@ -2824,16 +2829,22 @@ CacheIndex::BuildIndex()
     rv = file->GetNativeLeafName(leaf);
     if (NS_FAILED(rv)) {
       LOG(("CacheIndex::BuildIndex() - GetNativeLeafName() failed! Skipping "
            "file."));
       mDontMarkIndexClean = true;
       continue;
     }
 
+    if (!fileExists) {
+      LOG(("CacheIndex::BuildIndex() - File returned by the iterator was "
+           "removed in the meantime [name=%s]", leaf.get()));
+      continue;
+    }
+
     SHA1Sum::Hash hash;
     rv = CacheFileIOManager::StrToHash(leaf, &hash);
     if (NS_FAILED(rv)) {
       LOG(("CacheIndex::BuildIndex() - Filename is not a hash, removing file. "
            "[name=%s]", leaf.get()));
       file->Remove(false);
       continue;
     }
@@ -2897,16 +2908,17 @@ CacheIndex::BuildIndex()
       file->Remove(false);
     } else {
       CacheIndexEntryAutoManage entryMng(&hash, this);
       entry = mIndex.PutEntry(hash);
       if (NS_FAILED(InitEntryFromDiskData(entry, meta, size))) {
         LOG(("CacheIndex::BuildIndex() - CacheFile::InitEntryFromDiskData() "
              "failed, removing file. [name=%s]", leaf.get()));
         file->Remove(false);
+        entry->MarkRemoved();
       } else {
         LOG(("CacheIndex::BuildIndex() - Added entry to index. [name=%s]",
              leaf.get()));
         entry->Log();
       }
     }
   }
 
@@ -3018,21 +3030,26 @@ CacheIndex::UpdateIndex()
   while (true) {
     if (CacheIOThread::YieldAndRerun()) {
       LOG(("CacheIndex::UpdateIndex() - Breaking loop for higher level "
            "events."));
       mUpdateEventPending = true;
       return;
     }
 
+    bool fileExists = false;
     nsCOMPtr<nsIFile> file;
     {
       // Do not do IO under the lock.
       StaticMutexAutoUnlock unlock(sLock);
       rv = mDirEnumerator->GetNextFile(getter_AddRefs(file));
+
+      if (file) {
+        file->Exists(&fileExists);
+      }
     }
     if (mState == SHUTDOWN) {
       return;
     }
     if (!file) {
       FinishUpdate(NS_SUCCEEDED(rv));
       return;
     }
@@ -3041,16 +3058,22 @@ CacheIndex::UpdateIndex()
     rv = file->GetNativeLeafName(leaf);
     if (NS_FAILED(rv)) {
       LOG(("CacheIndex::UpdateIndex() - GetNativeLeafName() failed! Skipping "
            "file."));
       mDontMarkIndexClean = true;
       continue;
     }
 
+    if (!fileExists) {
+      LOG(("CacheIndex::UpdateIndex() - File returned by the iterator was "
+           "removed in the meantime [name=%s]", leaf.get()));
+      continue;
+    }
+
     SHA1Sum::Hash hash;
     rv = CacheFileIOManager::StrToHash(leaf, &hash);
     if (NS_FAILED(rv)) {
       LOG(("CacheIndex::UpdateIndex() - Filename is not a hash, removing file. "
            "[name=%s]", leaf.get()));
       file->Remove(false);
       continue;
     }