Commit d9111de5 authored by Bruce Dawson's avatar Bruce Dawson Committed by Commit Bot

Handle known TerminateProcess "failure" case

If a process has already gone away when you call TerminateProcess then
TerminateProcess will fail with error code 5. This seems unintuitive to
me and the resulting error spew when running tests can be misleading.

This change avoids printing the message when GetLastError() is
ERROR_ACCESS_DENIED to avoids the spuriuos debug spew.

This was noticed while investigating crbug.com/861730

Change-Id: I869073bd3c6b0c00ceeee7d7f1139e3091e3a1cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662974
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#670279}
parent dfbfd505
......@@ -165,10 +165,14 @@ bool Process::Terminate(int exit_code, bool wait) const {
DPLOG(ERROR) << "Error waiting for process exit";
Exited(exit_code);
} else {
// The process can't be terminated, perhaps because it has already
// exited or is in the process of exiting. A non-zero timeout is necessary
// here for the same reasons as above.
DPLOG(ERROR) << "Unable to terminate process";
// The process can't be terminated, perhaps because it has already exited or
// is in the process of exiting. An error code of ERROR_ACCESS_DENIED is the
// undocumented-but-expected result if the process has already exited or
// started exiting when TerminateProcess is called, so don't print an error
// message in that case.
if (GetLastError() != ERROR_ACCESS_DENIED)
DPLOG(ERROR) << "Unable to terminate process";
// A non-zero timeout is necessary here for the same reasons as above.
if (::WaitForSingleObject(Handle(), kWaitMs) == WAIT_OBJECT_0) {
DWORD actual_exit;
Exited(::GetExitCodeProcess(Handle(), &actual_exit) ? actual_exit
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment