Bug 1276920 - Limit number of tries to find unused file name for doomed entry file, r=honzab a=sylvestre CLOSED TREE
authorMichal Novotny <michal.novotny@gmail.com>
Sat, 30 Jul 2016 00:55:46 +0200
changeset 335704 b66e4f53fe15
parent 335703 9bf4d2171f27
child 335705 0253fd92571a
push id1158
push userkwierso@gmail.com
push dateFri, 12 Aug 2016 22:45:50 +0000
treeherdermozilla-release@b66e4f53fe15 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab, sylvestre
bugs1276920
milestone48.0.1
Bug 1276920 - Limit number of tries to find unused file name for doomed entry file, r=honzab a=sylvestre CLOSED TREE
netwerk/cache2/CacheFileIOManager.cpp
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -3588,35 +3588,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());