Bug 1246778 - dont loop in nshttpconnection during shutdown r=dragana a=sylvestre
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 08 Feb 2016 17:21:43 -0500
changeset 304056 b11173de517e8def090034753cb7003903b835df
parent 304055 183008d0c4888610d7d2b0814a3036b0ec25ca10
child 304057 f9114bdcff3ba11deb915ca4b434a717882f74eb
push id9099
push userkwierso@gmail.com
push dateThu, 18 Feb 2016 21:22:11 +0000
treeherdermozilla-aurora@707e82be734d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, sylvestre
bugs1246778
milestone46.0a2
Bug 1246778 - dont loop in nshttpconnection during shutdown r=dragana a=sylvestre
netwerk/protocol/http/nsHttpConnection.cpp
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
--- a/netwerk/protocol/http/nsHttpConnection.cpp
+++ b/netwerk/protocol/http/nsHttpConnection.cpp
@@ -1642,17 +1642,17 @@ nsHttpConnection::OnSocketWritable()
                                                 NS_NET_STATUS_WAITING_FOR,
                                                 0);
 
                 rv = ResumeRecv(); // start reading
             }
             again = false;
         }
         // write more to the socket until error or end-of-request...
-    } while (again);
+    } while (again && gHttpHandler->Active());
 
     return rv;
 }
 
 nsresult
 nsHttpConnection::OnWriteSegment(char *buf,
                                  uint32_t count,
                                  uint32_t *countWritten)
@@ -1781,17 +1781,17 @@ nsHttpConnection::OnSocketReadable()
                 if (mSocketInCondition == NS_BASE_STREAM_WOULD_BLOCK)
                     rv = ResumeRecv();
                 else
                     rv = mSocketInCondition;
                 again = false;
             }
         }
         // read more from the socket until error...
-    } while (again);
+    } while (again && gHttpHandler->Active());
 
     return rv;
 }
 
 void
 nsHttpConnection::SetupSecondaryTLS()
 {
     MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -171,20 +171,20 @@ nsHttpHandler::nsHttpHandler()
     , mCompatFirefoxEnabled(false)
     , mUserAgentIsDirty(true)
     , mPromptTempRedirect(true)
     , mSendSecureXSiteReferrer(true)
     , mEnablePersistentHttpsCaching(false)
     , mDoNotTrackEnabled(false)
     , mSafeHintEnabled(false)
     , mParentalControlEnabled(false)
+    , mHandlerActive(false)
     , mTelemetryEnabled(false)
     , mAllowExperiments(true)
     , mDebugObservations(false)
-    , mHandlerActive(false)
     , mEnableSpdy(false)
     , mSpdyV31(true)
     , mHttp2Enabled(true)
     , mUseH2Deps(true)
     , mEnforceHttp2TlsProfile(true)
     , mCoalesceSpdy(true)
     , mSpdyPersistentSettings(false)
     , mAllowPush(true)
@@ -242,16 +242,17 @@ nsHttpHandler::~nsHttpHandler()
 }
 
 nsresult
 nsHttpHandler::Init()
 {
     nsresult rv;
 
     LOG(("nsHttpHandler::Init\n"));
+    MOZ_ASSERT(NS_IsMainThread());
 
     rv = nsHttp::CreateAtomTable();
     if (NS_FAILED(rv))
         return rv;
 
     nsCOMPtr<nsIIOService> service = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
     if (NS_FAILED(rv)) {
         NS_WARNING("unable to continue without io service");
@@ -2036,16 +2037,17 @@ nsHttpHandler::GetMisc(nsACString &value
 // nsHttpHandler::nsIObserver
 //-----------------------------------------------------------------------------
 
 NS_IMETHODIMP
 nsHttpHandler::Observe(nsISupports *subject,
                        const char *topic,
                        const char16_t *data)
 {
+    MOZ_ASSERT(NS_IsMainThread());
     LOG(("nsHttpHandler::Observe [topic=\"%s\"]\n", topic));
 
     if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
         nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(subject);
         if (prefBranch)
             PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get());
     } else if (!strcmp(topic, "profile-change-net-teardown") ||
                !strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) ) {
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -474,28 +474,28 @@ private:
 
     // For broadcasting tracking preference
     bool           mDoNotTrackEnabled;
 
     // for broadcasting safe hint;
     bool           mSafeHintEnabled;
     bool           mParentalControlEnabled;
 
+    // true in between init and shutdown states
+    Atomic<bool, Relaxed> mHandlerActive;
+
     // Whether telemetry is reported or not
     uint32_t           mTelemetryEnabled : 1;
 
     // The value of network.allow-experiments
     uint32_t           mAllowExperiments : 1;
 
     // The value of 'hidden' network.http.debug-observations : 1;
     uint32_t           mDebugObservations : 1;
 
-    // true in between init and shutdown states
-    uint32_t           mHandlerActive : 1;
-
     uint32_t           mEnableSpdy : 1;
     uint32_t           mSpdyV31 : 1;
     uint32_t           mHttp2Enabled : 1;
     uint32_t           mUseH2Deps : 1;
     uint32_t           mEnforceHttp2TlsProfile : 1;
     uint32_t           mCoalesceSpdy : 1;
     uint32_t           mSpdyPersistentSettings : 1;
     uint32_t           mAllowPush : 1;