Bug 1782181 - Part 2: Notify nsMultiplexInputStream callbacks if AsyncWait fails, r=asuth, a=dsmith
authorNika Layzell <nika@thelayzells.com>
Wed, 03 Aug 2022 19:36:29 +0000
changeset 696128 f028f909c84fdf1aaf6ee8c0bdba9d21a9c8873d
parent 696127 7b0014abc20e0d7302ec7eb0bf9c1abff21c07bd
child 696129 33058780595e93bd440bf4a6c284edd2df0914d3
push id16931
push userdsmith@mozilla.com
push dateThu, 04 Aug 2022 18:37:42 +0000
treeherdermozilla-beta@f028f909c84f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth, dsmith
bugs1782181
milestone104.0
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
--- a/xpcom/io/nsMultiplexInputStream.cpp
+++ b/xpcom/io/nsMultiplexInputStream.cpp
@@ -921,26 +921,31 @@ nsMultiplexInputStream::OnInputStreamRea
         // otherwise re-wait on the current stream until it has data available
         // or becomes closed.
         // Unlike streams not implementing nsIAsyncInputStream, async streams
         // cannot use `Available() == 0` to indicate EOF, so we re-poll in that
         // situation.
         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;
+        }
       }
     }
 
     mAsyncWaitCallback.swap(callback);
     mAsyncWaitEventTarget = nullptr;
   }
 
-  return callback->OnInputStreamReady(this);
+  return callback ? callback->OnInputStreamReady(this) : NS_OK;
 }
 
 void nsMultiplexInputStream::AsyncWaitCompleted() {
   nsCOMPtr<nsIInputStreamCallback> callback;
 
   {
     MutexAutoLock lock(mLock);