Bug 1276920 - Limit number of tries to find unused file name for doomed entry file, r=honzab a=sylvestre
authorMichal Novotny <michal.novotny@gmail.com>
Sat, 30 Jul 2016 00:55:46 +0200
changeset 340299 120810e0a289
parent 340298 d28c4c3dc457
child 340300 b985e6deb20d
push id6292
push userkwierso@gmail.com
push dateFri, 12 Aug 2016 22:45:29 +0000
treeherdermozilla-beta@b985e6deb20d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab, sylvestre
bugs1276920
milestone49.0
Bug 1276920 - Limit number of tries to find unused file name for doomed entry file, r=honzab a=sylvestre
netwerk/cache2/CacheFileIOManager.cpp
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -3589,35 +3589,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());