From a2bdc46cf96498baf8fc211bcc9e00aa408baa5e Mon Sep 17 00:00:00 2001 From: Nika Layzell <nika@thelayzells.com> Date: Wed, 3 Aug 2022 19:36:29 +0000 Subject: [PATCH] Bug 1782181 - Part 2: Notify nsMultiplexInputStream callbacks if AsyncWait fails, r=asuth, a=dsmith When `nsMultiplexInputStream` calls `AsyncWait` from within `OnInputStreamReady`, it is possible for those calls to fail. In that case, we will fail to notify AsyncWait listeners, which could lead to leaks or stream hangs. This patch changes the error handling in this situation to instead fire a pending stream callback after an error when re-dispatching `AsyncWait`. Depends on D153628 Differential Revision: https://phabricator.services.mozilla.com/D153629 --- xpcom/io/nsMultiplexInputStream.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/xpcom/io/nsMultiplexInputStream.cpp b/xpcom/io/nsMultiplexInputStream.cpp index 0d139fe0daaae..0f0d6c4f34327 100644 --- a/xpcom/io/nsMultiplexInputStream.cpp +++ b/xpcom/io/nsMultiplexInputStream.cpp @@ -926,8 +926,13 @@ nsMultiplexInputStream::OnInputStreamReady(nsIAsyncInputStream* aStream) { if (NS_FAILED(rv)) { NextStream(); } + + // Unlock and invoke AsyncWaitInternal to wait again. If this succeeds, + // we'll be called again, otherwise fall through and notify. MutexAutoUnlock unlock(mLock); - return AsyncWaitInternal(); + if (NS_SUCCEEDED(AsyncWaitInternal())) { + return NS_OK; + } } } @@ -935,7 +940,7 @@ nsMultiplexInputStream::OnInputStreamReady(nsIAsyncInputStream* aStream) { mAsyncWaitEventTarget = nullptr; } - return callback->OnInputStreamReady(this); + return callback ? callback->OnInputStreamReady(this) : NS_OK; } void nsMultiplexInputStream::AsyncWaitCompleted() { -- GitLab