Bug 1633644 - P2. Do not call RedirectToRealChannel if the channel got cancelled. r=mattwoodrow.
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 28 Apr 2020 22:31:55 +0000
changeset 526583 6e69838359fc41ce1a3066ad8cc071bfe6fc3250
parent 526582 f61aa96e84f558d825bc7b3c5bb653695ef09519
child 526584 8ddb472bac121045da53568c3367e30929408e23
push id37358
push useropoprus@mozilla.com
push dateWed, 29 Apr 2020 03:05:14 +0000
treeherdermozilla-central@6bb8423186c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1633644
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1633644 - P2. Do not call RedirectToRealChannel if the channel got cancelled. r=mattwoodrow. Depends on D72795 Differential Revision: https://phabricator.services.mozilla.com/D72809
netwerk/ipc/DocumentLoadListener.cpp
netwerk/ipc/DocumentLoadListener.h
--- a/netwerk/ipc/DocumentLoadListener.cpp
+++ b/netwerk/ipc/DocumentLoadListener.cpp
@@ -695,16 +695,18 @@ void DocumentLoadListener::DocumentChann
   }
 }
 
 void DocumentLoadListener::Cancel(const nsresult& aStatusCode) {
   LOG(
       ("DocumentLoadListener Cancel [this=%p, "
        "aStatusCode=%" PRIx32 " ]",
        this, static_cast<uint32_t>(aStatusCode)));
+  mCancelled = true;
+
   if (mDoingProcessSwitch) {
     // If we've already initiated process-switching
     // then we can no longer be cancelled and we'll
     // disconnect the old listeners when done.
     return;
   }
 
   if (mChannel) {
@@ -1426,18 +1428,23 @@ DocumentLoadListener::RedirectToRealChan
     }
 
     return cp->SendCrossProcessRedirect(args,
                                         std::move(aStreamFilterEndpoints));
   }
 
   return EnsureBridge()->Then(
       GetCurrentThreadSerialEventTarget(), __func__,
-      [endpoints = std::move(aStreamFilterEndpoints), aRedirectFlags,
+      [self = RefPtr<DocumentLoadListener>(this),
+       endpoints = std::move(aStreamFilterEndpoints), aRedirectFlags,
        aLoadFlags](ADocumentChannelBridge* aBridge) mutable {
+        if (self->mCancelled) {
+          return PDocumentChannelParent::RedirectToRealChannelPromise::
+              CreateAndResolve(NS_BINDING_ABORTED, __func__);
+        }
         return aBridge->RedirectToRealChannel(std::move(endpoints),
                                               aRedirectFlags, aLoadFlags);
       },
       [](bool aDummy) {
         return PDocumentChannelParent::RedirectToRealChannelPromise::
             CreateAndReject(ipc::ResponseRejectReason::ActorDestroyed,
                             __func__);
       });
--- a/netwerk/ipc/DocumentLoadListener.h
+++ b/netwerk/ipc/DocumentLoadListener.h
@@ -429,16 +429,19 @@ class DocumentLoadListener : public nsII
   // Set to true if we've received OnStopRequest, and shouldn't
   // setup a reference from the ParentChannelListener to the replacement
   // channel.
   bool mIsFinished = false;
 
   // This identifier is set by MaybeTriggerProcessSwitch, and is later
   // passed to the childChannel in order to identify it in the new process.
   uint64_t mCrossProcessRedirectIdentifier = 0;
+
+  // True if cancelled.
+  bool mCancelled = false;
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(DocumentLoadListener, DOCUMENT_LOAD_LISTENER_IID)
 
 inline nsISupports* ToSupports(DocumentLoadListener* aObj) {
   return static_cast<nsIInterfaceRequestor*>(aObj);
 }