Commit 6c8f3b9c authored by Brian White's avatar Brian White Committed by Commit Bot

Add timeout waiting for exit of process.

Turns out that there are cases where a process has started exiting (and
thus can't be terminated) but still isn't ready to be reaped.  Thus, a
wait timeout is required in this case as well.

Bug: 757946
Change-Id: Iaf79092a991200c14d321963d9a20bfc191867bc
Reviewed-on: https://chromium-review.googlesource.com/803837Reviewed-by: default avatarMark Mentovai <mark@chromium.org>
Commit-Queue: Brian White <bcwhite@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521001}
parent 96f45d22
...@@ -132,19 +132,22 @@ void Process::Close() { ...@@ -132,19 +132,22 @@ void Process::Close() {
} }
bool Process::Terminate(int exit_code, bool wait) const { bool Process::Terminate(int exit_code, bool wait) const {
constexpr DWORD kWaitMs = 60 * 1000;
// exit_code cannot be implemented. // exit_code cannot be implemented.
DCHECK(IsValid()); DCHECK(IsValid());
bool result = (::TerminateProcess(Handle(), exit_code) != FALSE); bool result = (::TerminateProcess(Handle(), exit_code) != FALSE);
if (result) { if (result) {
// The process may not end immediately due to pending I/O // The process may not end immediately due to pending I/O
if (wait && ::WaitForSingleObject(Handle(), 60 * 1000) != WAIT_OBJECT_0) if (wait && ::WaitForSingleObject(Handle(), kWaitMs) != WAIT_OBJECT_0)
DPLOG(ERROR) << "Error waiting for process exit"; DPLOG(ERROR) << "Error waiting for process exit";
Exited(exit_code); Exited(exit_code);
} else { } else {
// The process can't be terminated, perhaps because it has already // The process can't be terminated, perhaps because it has already
// exited. // 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"; DPLOG(ERROR) << "Unable to terminate process";
if (::WaitForSingleObject(Handle(), 0) == WAIT_OBJECT_0) { if (::WaitForSingleObject(Handle(), kWaitMs) == WAIT_OBJECT_0) {
DWORD actual_exit; DWORD actual_exit;
Exited(::GetExitCodeProcess(Handle(), &actual_exit) ? actual_exit Exited(::GetExitCodeProcess(Handle(), &actual_exit) ? actual_exit
: exit_code); : exit_code);
......
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