[tbb-commits] [tor-browser] 42/46: Bug 1791314, some underlying streams prefer being closed on the target thread, r=valentin, necko-reviewers, a=dmeehan

gitolite role git at cupani.torproject.org
Wed Nov 16 20:43:22 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch base-browser-102.5.0esr-12.0-1
in repository tor-browser.

commit 86f741ce7791584a1cddf3badaf455a82fb950e9
Author: Olli Pettay <Olli.Pettay at helsinki.fi>
AuthorDate: Thu Oct 27 08:40:35 2022 +0000

    Bug 1791314, some underlying streams prefer being closed on the target thread, r=valentin,necko-reviewers, a=dmeehan
    
    Differential Revision: https://phabricator.services.mozilla.com/D160054
---
 netwerk/base/nsInputStreamPump.cpp | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/netwerk/base/nsInputStreamPump.cpp b/netwerk/base/nsInputStreamPump.cpp
index ce6a4d6dcaa3..a0d21172d63b 100644
--- a/netwerk/base/nsInputStreamPump.cpp
+++ b/netwerk/base/nsInputStreamPump.cpp
@@ -185,12 +185,31 @@ nsInputStreamPump::Cancel(nsresult status) {
 
   // close input stream
   if (mAsyncStream) {
-    mAsyncStream->CloseWithStatus(status);
-    if (mSuspendCount == 0) EnsureWaiting();
-    // Otherwise, EnsureWaiting will be called by Resume().
+    // If mSuspendCount != 0, EnsureWaiting will be called by Resume().
     // Note that while suspended, OnInputStreamReady will
     // not do anything, and also note that calling asyncWait
     // on a closed stream works and will dispatch an event immediately.
+
+    nsCOMPtr<nsIEventTarget> currentTarget = NS_GetCurrentThread();
+    if (mTargetThread && currentTarget != mTargetThread) {
+      nsresult rv = mTargetThread->Dispatch(NS_NewRunnableFunction(
+          "nsInputStreamPump::Cancel", [self = RefPtr{this}, status] {
+            RecursiveMutexAutoLock lock(self->mMutex);
+            if (!self->mAsyncStream) {
+              return;
+            }
+            self->mAsyncStream->CloseWithStatus(status);
+            if (self->mSuspendCount == 0) {
+              self->EnsureWaiting();
+            }
+          }));
+      NS_ENSURE_SUCCESS(rv, rv);
+    } else {
+      mAsyncStream->CloseWithStatus(status);
+      if (mSuspendCount == 0) {
+        EnsureWaiting();
+      }
+    }
   }
   return NS_OK;
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list