diff --git a/device/gamepad/hid_writer_win.cc b/device/gamepad/hid_writer_win.cc index 420f6372202d6..c213f89835707 100644 --- a/device/gamepad/hid_writer_win.cc +++ b/device/gamepad/hid_writer_win.cc @@ -62,13 +62,15 @@ size_t HidWriterWin::WriteOutputReport(base::span report) { true); } else { // Wait failed, or the timeout was exceeded before the write completed. - // Cancel the write request. - if (::CancelIo(hid_handle_.Get())) { - HANDLE handles[2]; - handles[0] = hid_handle_.Get(); - handles[1] = overlapped.hEvent; - ::WaitForMultipleObjects(2, handles, false, INFINITE); - } + // Cancel the write request. CancelIo() only marks outstanding IO for + // cancellation; it does not wait for the kernel to finish writing the + // IO_STATUS_BLOCK into |overlapped|. We must block on + // GetOverlappedResult() so the stack-allocated OVERLAPPED and its + // event handle outlive IRP completion. + ::CancelIo(hid_handle_.Get()); + DWORD unused = 0; + ::GetOverlappedResult(hid_handle_.Get(), &overlapped, &unused, + /*bWait=*/TRUE); } } }