win: Add timeout argument to WaitForHandlerStart()

As brought up in https://codereview.chromium.org/2475863004/, there's
the potential for failed startup if StartHandlerProcess() hangs for
whatever reason. Add a timeout to the wait function so that this case
can attempt to log an error.

R=mark@chromium.org
BUG=655788, 656800, 565063

Change-Id: Ib08cd0641daa6a6cefabb773ffe470227b51958c
Reviewed-on: https://chromium-review.googlesource.com/419060
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Scott Graham 2016-12-12 20:57:48 -08:00
parent 32981a3ee9
commit cdbb90ec69
3 changed files with 14 additions and 5 deletions

View File

@ -173,9 +173,12 @@ class CrashpadClient {
//! //!
//! This method should not be used unless `asynchronous_start` was `true`. //! This method should not be used unless `asynchronous_start` was `true`.
//! //!
//! \param[in] timeout_ms The number of milliseconds to wait for a result from
//! the background launch, or `0xffffffff` to block indefinitely.
//!
//! \return `true` if the hander startup succeeded, `false` otherwise, and an //! \return `true` if the hander startup succeeded, `false` otherwise, and an
//! error message will have been logged. //! error message will have been logged.
bool WaitForHandlerStart(); bool WaitForHandlerStart(unsigned int timeout_ms);
//! \brief Requests that the handler capture a dump even though there hasn't //! \brief Requests that the handler capture a dump even though there hasn't
//! been a crash. //! been a crash.

View File

@ -689,10 +689,16 @@ std::wstring CrashpadClient::GetHandlerIPCPipe() const {
return ipc_pipe_; return ipc_pipe_;
} }
bool CrashpadClient::WaitForHandlerStart() { bool CrashpadClient::WaitForHandlerStart(unsigned int timeout_ms) {
DCHECK(handler_start_thread_.is_valid()); DCHECK(handler_start_thread_.is_valid());
if (WaitForSingleObject(handler_start_thread_.get(), INFINITE) != DWORD result = WaitForSingleObject(handler_start_thread_.get(), timeout_ms);
WAIT_OBJECT_0) { if (result == WAIT_TIMEOUT) {
LOG(ERROR) << "WaitForSingleObject timed out";
return false;
} else if (result == WAIT_ABANDONED) {
LOG(ERROR) << "WaitForSingleObject abandoned";
return false;
} else if (result != WAIT_OBJECT_0) {
PLOG(ERROR) << "WaitForSingleObject"; PLOG(ERROR) << "WaitForSingleObject";
return false; return false;
} }

View File

@ -39,7 +39,7 @@ void StartAndUseHandler() {
std::vector<std::string>(), std::vector<std::string>(),
true, true,
true)); true));
ASSERT_TRUE(client.WaitForHandlerStart()); ASSERT_TRUE(client.WaitForHandlerStart(INFINITE));
} }
class StartWithInvalidHandles final : public WinMultiprocess { class StartWithInvalidHandles final : public WinMultiprocess {