Bug 1276920 - Limit number of tries to find unused file name for doomed entry file, r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Sat, 30 Jul 2016 00:55:46 +0200
changeset 347404 6b2d6afdd59b9cfba22e49d09cf3a892835db9d0
parent 347403 fb2ed37447b7445070d251072459de8a9e9983c0
child 347405 5f0c9095c0ff59de08caa34270c6139deef86f3b
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1276920
milestone50.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 1276920 - Limit number of tries to find unused file name for doomed entry file, r=honzab
netwerk/cache2/CacheFileIOManager.cpp
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -3598,35 +3598,38 @@ CacheFileIOManager::GetDoomedFile(nsIFil
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = file->AppendNative(NS_LITERAL_CSTRING(DOOMED_DIR));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = file->AppendNative(NS_LITERAL_CSTRING("dummyleaf"));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  const int32_t kMaxTries = 64;
   srand(static_cast<unsigned>(PR_Now()));
   nsAutoCString leafName;
-  uint32_t iter=0;
-  while (true) {
-    iter++;
+  for (int32_t triesCount = 0; ; ++triesCount) {
     leafName.AppendInt(rand());
     rv = file->SetNativeLeafName(leafName);
     NS_ENSURE_SUCCESS(rv, rv);
 
     bool exists;
     if (NS_SUCCEEDED(file->Exists(&exists)) && !exists) {
       break;
     }
 
+    if (triesCount == kMaxTries) {
+      LOG(("CacheFileIOManager::GetDoomedFile() - Could not find unused file "
+           "name in %d tries.", kMaxTries));
+      return NS_ERROR_FAILURE;
+    }
+
     leafName.Truncate();
   }
 
-//  Telemetry::Accumulate(Telemetry::DISK_CACHE_GETDOOMEDFILE_ITERATIONS, iter);
-
   file.swap(*_retval);
   return NS_OK;
 }
 
 nsresult
 CacheFileIOManager::IsEmptyDirectory(nsIFile *aFile, bool *_retval)
 {
   MOZ_ASSERT(mIOThread->IsCurrentThread());