Bug 1611651 - Make sure channels doing a stale-while-revalidate cannot trigger another revalidation r=dragana a=jcristau
authorValentin Gosu <valentin.gosu@gmail.com>
Tue, 10 Mar 2020 11:37:19 +0000
changeset 580700 a22e626aa75f68f28359e508d3efe4fffceae7c2
parent 580699 f39beaef9ee199b3c118c5c7892fd3d92cc17860
child 580701 aca558d69c1be8083c3b56fb86c84cc88051032d
push id12925
push usermalexandru@mozilla.com
push dateThu, 26 Mar 2020 11:24:04 +0000
treeherdermozilla-beta@acafefc48432 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, jcristau
bugs1611651
milestone75.0
Bug 1611651 - Make sure channels doing a stale-while-revalidate cannot trigger another revalidation r=dragana a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D65814
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -10570,16 +10570,21 @@ NS_IMPL_ISUPPORTS(BackgroundRevalidating
 
 }  // namespace
 
 void nsHttpChannel::PerformBackgroundCacheRevalidation() {
   if (!StaticPrefs::network_http_stale_while_revalidate_enabled()) {
     return;
   }
 
+  // This is a channel doing a revalidation. It shouldn't do it again.
+  if (mStaleRevalidation) {
+    return;
+  }
+
   LOG(("nsHttpChannel::PerformBackgroundCacheRevalidation %p", this));
 
   Unused << NS_DispatchToMainThreadQueue(
       NewIdleRunnableMethod(
           "nsHttpChannel::PerformBackgroundCacheRevalidation", this,
           &nsHttpChannel::PerformBackgroundCacheRevalidationNow),
       EventQueuePriority::Idle);
 }
@@ -10609,16 +10614,21 @@ void nsHttpChannel::PerformBackgroundCac
     priority->SetPriority(nsISupportsPriority::PRIORITY_LOWEST);
   }
 
   nsCOMPtr<nsIClassOfService> cos(do_QueryInterface(validatingChannel));
   if (cos) {
     cos->AddClassFlags(nsIClassOfService::Tail);
   }
 
+  RefPtr<nsHttpChannel> httpChan = do_QueryObject(validatingChannel);
+  if (httpChan) {
+    httpChan->mStaleRevalidation = true;
+  }
+
   RefPtr<BackgroundRevalidatingListener> listener =
       new BackgroundRevalidatingListener();
   rv = validatingChannel->AsyncOpen(listener);
   if (NS_FAILED(rv)) {
     LOG(("  failed to open the channel, rv=0x%08x", static_cast<uint32_t>(rv)));
     return;
   }
 
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -821,16 +821,17 @@ class nsHttpChannel final : public HttpB
   nsresult TriggerNetwork();
   void CancelNetworkRequest(nsresult aStatus);
   // Timer used to delay the network request, or to trigger the network
   // request if retrieving the cache entry takes too long.
   nsCOMPtr<nsITimer> mNetworkTriggerTimer;
   // Is true if the network request has been triggered.
   bool mNetworkTriggered = false;
   bool mWaitingForProxy = false;
+  bool mStaleRevalidation = false;
   // Will be true if the onCacheEntryAvailable callback is not called by the
   // time we send the network request
   Atomic<bool> mRaceCacheWithNetwork;
   uint32_t mRaceDelay;
   // If true then OnCacheEntryAvailable should ignore the entry, because
   // SetupTransaction removed conditional headers and decisions made in
   // OnCacheEntryCheck are no longer valid.
   bool mIgnoreCacheEntry;