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 506981 c8e66d503efd
parent 506980 8e32d7856fd8
child 506982 77623171e512
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [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();
   }