Bug 722034 - Part 8 - Work around bug 759805, r=michal
authorBrian Smith <bsmith@mozilla.com>
Thu, 31 May 2012 22:12:01 -0700
changeset 95374 73783bf75c4cb7a186f4b59e0b0f918a3d7839ff
parent 95373 4bedfde602cde0344e55d5302ff8a7c9ad55818f
child 95375 cb648ec7d7f2b2997d664546555e551715ee5e36
push id22807
push userbsmith@mozilla.com
push dateFri, 01 Jun 2012 06:44:42 +0000
treeherdermozilla-central@73783bf75c4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs722034, 759805
milestone15.0a1
first release with
nightly linux32
73783bf75c4c / 15.0a1 / 20120601030520 / files
nightly linux64
73783bf75c4c / 15.0a1 / 20120601030520 / files
nightly mac
73783bf75c4c / 15.0a1 / 20120601030520 / files
nightly win32
73783bf75c4c / 15.0a1 / 20120601030520 / files
nightly win64
73783bf75c4c / 15.0a1 / 20120601030520 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 722034 - Part 8 - Work around bug 759805, r=michal
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -196,16 +196,17 @@ public:
         , mCacheKey(cacheKey)
         , mAccessToRequest(accessToRequest)
         , mNoWait(noWait)
         , mUsingSSL(usingSSL)
         , mLoadedFromApplicationCache(loadedFromApplicationCache)
         // internal
         , mCacheAccess(0)
         , mStatus(NS_ERROR_NOT_INITIALIZED)
+        , mRunCount(0)
         // in/out
         , mRequestHead(channel->mRequestHead)
         , mRedirectedCachekeys(channel->mRedirectedCachekeys.forget())
         // out
         , mCachedContentIsValid(false)
         , mCachedContentIsPartial(false)
         , mCustomConditionalRequest(false)
         , mDidReval(false)
@@ -253,16 +254,17 @@ private:
     const bool mUsingSSL;
     const bool mLoadedFromApplicationCache;
 
     // Used only internally 
     nsCOMPtr<nsIEventTarget> mCacheThread;
     nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;
     nsCacheAccessMode mCacheAccess;
     nsresult mStatus;
+    PRUint32 mRunCount;
 
     // Copied from HttpcacheQuery into nsHttpChannel by nsHttpChannel
     friend class nsHttpChannel;
     /*in/out*/ nsHttpRequestHead mRequestHead;
     /*in/out*/ nsAutoPtr<nsTArray<nsCString> > mRedirectedCachekeys;
     /*out*/ AutoClose<nsIAsyncInputStream> mCacheAsyncInputStream;
     /*out*/ nsAutoPtr<nsHttpResponseHead> mCachedResponseHead;
     /*out*/ nsCOMPtr<nsISupports> mCachedSecurityInfo;
@@ -2806,16 +2808,18 @@ HttpCacheQuery::Run()
         }
         if (NS_SUCCEEDED(rv)) {
             // AsyncOpenCacheEntry isn't really async when its called on the
             // cache service thread.
             rv = session->AsyncOpenCacheEntry(mCacheKey, mAccessToRequest, this,
                                               mNoWait);
         }
         if (NS_FAILED(rv)) {
+            LOG(("Failed to open cache entry -- calling OnCacheEntryAvailable "
+                 "directly."));
             rv = OnCacheEntryAvailable(nsnull, 0, rv);
         }
     } else {
         // break cycles
         nsCOMPtr<nsICacheListener> channel = mChannel.forget();
         mCacheThread = nsnull;
         nsCOMPtr<nsICacheEntryDescriptor> entry = mCacheEntry.forget();
 
@@ -2826,21 +2830,29 @@ HttpCacheQuery::Run()
 }
 
 NS_IMETHODIMP
 HttpCacheQuery::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry,
                                       nsCacheAccessMode access,
                                       nsresult status)
 
 {
+    LOG(("HttpCacheQuery::OnCacheEntryAvailable [channel=%p entry=%p "
+         "access=%x status=%x, mRunConut=%d]\n", mChannel.get(), entry, access,
+         status, PRIntn(mRunCount)));
+
+    // XXX Bug 759805: Sometimes we will call this method directly from
+    // HttpCacheQuery::Run when AsyncOpenCacheEntry fails, but
+    // AsyncOpenCacheEntry will also call this method. As a workaround, we just
+    // ensure we only execute this code once.
+    NS_ENSURE_TRUE(mRunCount == 0, NS_ERROR_UNEXPECTED);
+    ++mRunCount;
+
     AssertOnCacheThread();
 
-    LOG(("HttpCacheQuery::OnCacheEntryAvailable [channel=%p entry=%p "
-         "access=%x status=%x]\n", mChannel.get(), entry, access, status));
-
     mCacheEntry = entry;
     mCacheAccess = access;
     mStatus = status;
 
     nsresult rv = CheckCache();
     if (NS_FAILED(rv))
         NS_WARNING("cache check failed");