Index: util/win/registration_protocol_win.cc |
diff --git a/util/win/registration_protocol_win.cc b/util/win/registration_protocol_win.cc |
index 3e0fdf213985a4bc81ae295bd3377140463045da..38b1b45195a6b86f2353da09e1da04e8f5f9252d 100644 |
--- a/util/win/registration_protocol_win.cc |
+++ b/util/win/registration_protocol_win.cc |
@@ -24,8 +24,8 @@ namespace crashpad { |
bool SendToCrashHandlerServer(const base::string16& pipe_name, |
const crashpad::ClientToServerMessage& message, |
crashpad::ServerToClientMessage* response) { |
- int tries = 5; |
- while (tries > 0) { |
+ int tries = 0; |
+ for (;;) { |
ScopedFileHANDLE pipe( |
CreateFile(pipe_name.c_str(), |
GENERIC_READ | GENERIC_WRITE, |
@@ -35,10 +35,20 @@ bool SendToCrashHandlerServer(const base::string16& pipe_name, |
SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, |
nullptr)); |
if (!pipe.is_valid()) { |
- Sleep(10); |
- --tries; |
+ if (++tries == 5 || GetLastError() != ERROR_PIPE_BUSY) { |
+ PLOG(ERROR) << "CreateFile"; |
+ return false; |
+ } |
+ |
+ if (!WaitNamedPipe(pipe_name.c_str(), 1000) && |
+ GetLastError() != ERROR_SEM_TIMEOUT) { |
+ PLOG(ERROR) << "WaitNamedPipe"; |
+ return false; |
+ } |
+ |
continue; |
} |
+ |
DWORD mode = PIPE_READMODE_MESSAGE; |
if (!SetNamedPipeHandleState(pipe.get(), &mode, nullptr, nullptr)) { |
PLOG(ERROR) << "SetNamedPipeHandleState"; |
@@ -55,7 +65,8 @@ bool SendToCrashHandlerServer(const base::string16& pipe_name, |
&bytes_read, |
nullptr); |
if (!result) { |
- PLOG(ERROR) << "TransactNamedPipe"; |
+ LOG(ERROR) << "TransactNamedPipe: expected " << sizeof(*response) |
+ << ", observed " << bytes_read; |
return false; |
} |
if (bytes_read != sizeof(*response)) { |
@@ -64,9 +75,6 @@ bool SendToCrashHandlerServer(const base::string16& pipe_name, |
} |
return true; |
} |
- |
- LOG(ERROR) << "failed to connect after retrying"; |
- return false; |
} |
} // namespace crashpad |