From 4842dfc9f68ed957fa4fc2e96a6033271241e59a Mon Sep 17 00:00:00 2001
From: Kershaw Chang <kershaw@mozilla.com>
Date: Tue, 13 Dec 2022 15:08:29 +0000
Subject: [PATCH] Bug 1769635 - Make sure AsyncAbort is always called,
 r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D164449
---
 layout/style/Loader.cpp                 |  6 +++---
 netwerk/protocol/http/nsHttpChannel.cpp | 13 +++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp
index 9a7de3ef0683e..aef1db7ea1421 100644
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -392,9 +392,9 @@ SheetLoadData::SheetLoadData(
 }
 
 SheetLoadData::~SheetLoadData() {
-  MOZ_DIAGNOSTIC_ASSERT(mSheetCompleteCalled || mIntentionallyDropped,
-                        "Should always call SheetComplete, except when "
-                        "dropping the load");
+  MOZ_RELEASE_ASSERT(mSheetCompleteCalled || mIntentionallyDropped,
+                     "Should always call SheetComplete, except when "
+                     "dropping the load");
 }
 
 NS_IMETHODIMP
diff --git a/netwerk/protocol/http/nsHttpChannel.cpp b/netwerk/protocol/http/nsHttpChannel.cpp
index 58459904b47a0..c668d1b1451ed 100644
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -5653,6 +5653,10 @@ nsresult nsHttpChannel::CancelInternal(nsresult status) {
         &mTransactionTimings, std::move(mSource));
   }
 
+  // If we don't have mTransactionPump and mCachePump, we need to call
+  // AsyncAbort to make sure this channel's listener got notified.
+  bool needAsyncAbort = !mTransactionPump && !mCachePump;
+
   if (mProxyRequest) mProxyRequest->Cancel(status);
   CancelNetworkRequest(status);
   mCacheInputStream.CloseAndRelease();
@@ -5663,10 +5667,19 @@ nsresult nsHttpChannel::CancelInternal(nsresult status) {
     mOnTailUnblock = nullptr;
     mRequestContext->CancelTailedRequest(this);
     CloseCacheEntry(false);
+    needAsyncAbort = false;
     Unused << AsyncAbort(status);
   } else if (channelClassifierCancellationPending) {
     // If we're coming from an asynchronous path when canceling a channel due
     // to safe-browsing protection, we need to AsyncAbort the channel now.
+    needAsyncAbort = false;
+    Unused << AsyncAbort(status);
+  }
+
+  // If we already have mCallOnResume, AsyncAbort will be called in
+  // ResumeInternal.
+  if (needAsyncAbort && !mCallOnResume) {
+    CloseCacheEntry(false);
     Unused << AsyncAbort(status);
   }
   return NS_OK;
-- 
GitLab