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
--- 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;
};