Bug 1268922 - Limit number of tries to find unused trash directory, r=honzab a=lizzard
authorMichal Novotny <michal.novotny@gmail.com>
Mon, 02 May 2016 19:58:58 +0200
changeset 332693 fb4552d95407a2a6ec0ef5b2924fc65797fc6e1e
parent 332692 28d54417440fbd929538bb85bedd281f21c05108
child 332694 2d3a15d3e47e3934aee718481471e14e11415870
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab, lizzard
bugs1268922
milestone48.0a2
Bug 1268922 - Limit number of tries to find unused trash directory, r=honzab a=lizzard
netwerk/cache2/CacheFileIOManager.cpp
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -3148,27 +3148,37 @@ CacheFileIOManager::TrashDirectory(nsIFi
   nsAutoCString leaf;
 
   rv = aFile->Clone(getter_AddRefs(dir));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = aFile->Clone(getter_AddRefs(trash));
   NS_ENSURE_SUCCESS(rv, rv);
 
+  const int32_t kMaxTries = 16;
   srand(static_cast<unsigned>(PR_Now()));
-  while (true) {
+  for (int32_t triesCount = 0; ; ++triesCount) {
     leaf = TRASH_DIR;
     leaf.AppendInt(rand());
     rv = trash->SetNativeLeafName(leaf);
     NS_ENSURE_SUCCESS(rv, rv);
 
     bool exists;
     if (NS_SUCCEEDED(trash->Exists(&exists)) && !exists) {
       break;
     }
+
+    LOG(("CacheFileIOManager::TrashDirectory() - Trash directory already "
+         "exists [leaf=%s]", leaf.get()));
+
+    if (triesCount == kMaxTries) {
+      LOG(("CacheFileIOManager::TrashDirectory() - Could not find unused trash "
+           "directory in %d tries.", kMaxTries));
+      return NS_ERROR_FAILURE;
+    }
   }
 
   LOG(("CacheFileIOManager::TrashDirectory() - Renaming directory [leaf=%s]",
        leaf.get()));
 
   rv = dir->MoveToNative(nullptr, leaf);
   NS_ENSURE_SUCCESS(rv, rv);