Bug 1354409 - Make sure nsHttpChannel::mRacingNetAndCache is only true when we are actually racing r=michal draft
authorValentin Gosu <valentin.gosu@gmail.com>
Fri, 21 Apr 2017 11:42:29 +0800
changeset 566215 47a604e25ce879b929dbb2eba7bca36e371845ae
parent 566214 5bfeed6c1fb8f1379844947bd391ac352700b411
child 625248 6d2c7c81cd8d2bfee0d6748db69710fd724620fa
push id55144
push uservalentin.gosu@gmail.com
push dateFri, 21 Apr 2017 06:47:37 +0000
reviewersmichal
bugs1354409
milestone55.0a1
Bug 1354409 - Make sure nsHttpChannel::mRacingNetAndCache is only true when we are actually racing r=michal mRacingNetAndCache used to be set in TriggerNetwork, when the network was triggered before the cache callbacks had been called, but this could also happen when we bypassed the cache. MozReview-Commit-ID: 4CklwPVRGar
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpChannel.h
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -8873,22 +8873,16 @@ nsHttpChannel::TriggerNetwork(int32_t aT
     LOG(("nsHttpChannel::TriggerNetwork [this=%p]\n", this));
     if (mNetworkTriggered) {
         LOG(("  network already triggered. Returning.\n"));
         return NS_OK;
     }
 
     if (!aTimeout) {
         mNetworkTriggered = true;
-        if (!mOnCacheAvailableCalled) {
-            // If the network was triggered before onCacheEntryAvailable was
-            // called, we are either racing network and cache, or the load is
-            // bypassing the cache.
-            mRaceCacheWithNetwork = true;
-        }
         if (mNetworkTriggerTimer) {
             mNetworkTriggerTimer->Cancel();
             mNetworkTriggerTimer = nullptr;
         }
 
         // If we are waiting for a proxy request, that means we can't trigger
         // the next step just yet. We need for mConnectionInfo to be non-null
         // before we call TryHSTSPriming. OnProxyAvailable will trigger
@@ -8924,23 +8918,35 @@ nsHttpChannel::MaybeRaceCacheWithNetwork
     // No need to trigger to trigger the racing, since most likely the cache
     // will be faster.
     if (mCacheQueueSizeWhenOpen < threshold) {
         return NS_OK;
     }
 
     MOZ_ASSERT(sRCWNEnabled, "The pref must be truned on.");
     LOG(("nsHttpChannel::MaybeRaceCacheWithNetwork [this=%p]\n", this));
+
+    if (!mOnCacheAvailableCalled) {
+        // If the network was triggered before onCacheEntryAvailable was
+        // called, it means we are racing the network with the cache.
+        mRaceCacheWithNetwork = true;
+    }
+
     return TriggerNetwork(0);
 }
 
 NS_IMETHODIMP
 nsHttpChannel::Test_triggerNetwork(int32_t aTimeout)
 {
     MOZ_ASSERT(NS_IsMainThread(), "Must be called on the main thread");
+    if (!mOnCacheAvailableCalled) {
+        // If the network was triggered before onCacheEntryAvailable was
+        // called, it means we are racing the network with the cache.
+        mRaceCacheWithNetwork = true;
+    }
     return TriggerNetwork(aTimeout);
 }
 
 NS_IMETHODIMP
 nsHttpChannel::Notify(nsITimer *aTimer)
 {
     RefPtr<nsHttpChannel> self(this);
     if (aTimer == mCacheOpenTimer) {
--- a/netwerk/protocol/http/nsHttpChannel.h
+++ b/netwerk/protocol/http/nsHttpChannel.h
@@ -674,18 +674,17 @@ private:
     // 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;
     // Is true if the onCacheEntryAvailable callback has been called.
     Atomic<bool> mOnCacheAvailableCalled;
     // Will be true if the onCacheEntryAvailable callback is not called by the
-    // time we send the network request. This could also be true when we are
-    // bypassing the cache.
+    // time we send the network request
     Atomic<bool> mRaceCacheWithNetwork;
 
 protected:
     virtual void DoNotifyListenerCleanup() override;
 
 private: // cache telemetry
     bool mDidReval;
 };