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 307335 6b2d6afdd59b
parent 307334 fb2ed37447b7
child 307336 5f0c9095c0ff
push id80082
push usermnovotny@mozilla.com
push dateFri, 29 Jul 2016 22:55:52 +0000
treeherdermozilla-inbound@6b2d6afdd59b [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());