Bug 1509277: Handle ERROR_INVALID_PARAMETER from OpenProcess differently from other errors in launcher process startup; r=cpearce
authorAaron Klotz <aklotz@mozilla.com>
Thu, 22 Nov 2018 22:37:04 +0000
changeset 504201 c8e66d503efd9abe025e5217198d06f6655e7b6b
parent 504200 8e32d7856fd8675929fb2521d022823bd43b4850
child 504202 77623171e512127f109569942fd4ae8468d2cf60
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1509277
milestone65.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 1509277: Handle ERROR_INVALID_PARAMETER from OpenProcess differently from other errors in launcher process startup; r=cpearce If the launcher process's parent process was ephemeral, the parent may have terminated before the launcher has a chance to open a handle to it. If so, OpenProcess will fail with ERROR_INVALID_PARAMETER, as the pid is now invalid. This is a common case, so instead of erroring out, IsSameBinaryAsParentProcess should treat this case as, "No, our parent was not a Firefox binary" and just return false. This eliminated the intermittent xpcshell failures on try. Differential Revision: https://phabricator.services.mozilla.com/D12714
browser/app/winlauncher/LauncherProcessWin.cpp
--- a/browser/app/winlauncher/LauncherProcessWin.cpp
+++ b/browser/app/winlauncher/LauncherProcessWin.cpp
@@ -153,17 +153,25 @@ IsSameBinaryAsParentProcess()
   mozilla::LauncherResult<DWORD> parentPid = mozilla::nt::GetParentProcessId();
   if (parentPid.isErr()) {
     return LAUNCHER_ERROR_FROM_RESULT(parentPid);
   }
 
   nsAutoHandle parentProcess(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
                                            FALSE, parentPid.unwrap()));
   if (!parentProcess.get()) {
-    return LAUNCHER_ERROR_FROM_LAST();
+    DWORD err = ::GetLastError();
+    if (err == ERROR_INVALID_PARAMETER) {
+      // The process identified by parentPid has already exited. This is a
+      // common case when the parent process is not Firefox, thus we should
+      // return false instead of erroring out.
+      return false;
+    }
+
+    return LAUNCHER_ERROR_FROM_WIN32(err);
   }
 
   WCHAR parentExe[MAX_PATH + 1] = {};
   DWORD parentExeLen = mozilla::ArrayLength(parentExe);
   if (!::QueryFullProcessImageNameW(parentProcess.get(), PROCESS_NAME_NATIVE,
                                     parentExe, &parentExeLen)) {
     return LAUNCHER_ERROR_FROM_LAST();
   }