Bug 1267930 - When the wasapi rendering loop is stuck and we're shuttin down, leak the thread and continue the shutdown process. r?kinetik
It's probably better to not TerminateThread here, because we don't really know
what happened down the stack of the rendering loop, so we just leak it. This
happens during shutdown so it's not really an issue, it's going to be cleaned
up by the OS anyways.
MozReview-Commit-ID: G8RZhitfASC
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -1173,17 +1173,25 @@ void stop_and_join_render_thread(cubeb_s
return;
}
BOOL ok = SetEvent(stm->shutdown_event);
if (!ok) {
LOG("Destroy SetEvent failed: %d\n", GetLastError());
}
- DWORD r = WaitForSingleObject(stm->thread, INFINITE);
+ /* Wait one second for the rendering thread to return. It's supposed to check
+ * its event loop very often, one second is rather conservative. */
+ DWORD r = WaitForSingleObject(stm->thread, 1000);
+ if (r == WAIT_TIMEOUT) {
+ /* Something weird happened, leak the thread and continue the shutdown
+ * process. */
+ LOG("Destroy WaitForSingleObject on thread timed out,"
+ " leaking the thread: %d\n", GetLastError());
+ }
if (r == WAIT_FAILED) {
LOG("Destroy WaitForSingleObject on thread failed: %d\n", GetLastError());
}
CloseHandle(stm->thread);
stm->thread = NULL;
CloseHandle(stm->shutdown_event);