Bug 1472889: Work around sporadic automation failures on Linux. r?erahm draft
authorKris Maglione <maglione.k@gmail.com>
Wed, 11 Jul 2018 17:39:05 -0700
changeset 817124 1930a63eb1095aa9b7566f7b0a8807a156a016ce
parent 817123 294a3fb2f045bef044cfbebe6fc6f1b1ee2be91b
push id115957
push usermaglione.k@gmail.com
push dateThu, 12 Jul 2018 02:06:13 +0000
reviewerserahm
bugs1472889
milestone63.0a1
Bug 1472889: Work around sporadic automation failures on Linux. r?erahm MozReview-Commit-ID: 1FrxRm95lqE
dom/ipc/MemMapSnapshot.cpp
--- a/dom/ipc/MemMapSnapshot.cpp
+++ b/dom/ipc/MemMapSnapshot.cpp
@@ -113,17 +113,29 @@ MemMapSnapshot::Freeze(AutoMemMap& aMem)
   // since we open and share a read-only file descriptor, and then delete the
   // file. But it doesn't hurt, either.
   chmod(mPath.get(), 0400);
 
   nsCOMPtr<nsIFile> file;
   MOZ_TRY(NS_NewNativeLocalFile(mPath, /* followLinks = */ false,
                                 getter_AddRefs(file)));
 
-  return aMem.init(file);
+  auto result = aMem.init(file);
+#ifdef XP_LINUX
+  // On Linux automation runs, every few hundred thousand calls, our attempt to
+  // stat the file that we just successfully opened fails with EBADF (bug
+  // 1472889). Presumably this is a race with a background thread that double
+  // closes a file, but is difficult to diagnose, so work around it by making a
+  // second mapping attempt if the first one fails.
+  if (!result.isOk()) {
+    aMem.reset();
+    result = aMem.init(file);
+  }
+#endif
+  return result;
 }
 
 #else
 #  error "Unsupported build configuration"
 #endif
 
 } // namespace ipc
 } // namespace mozilla