Bug 1246778 - dont loop in nshttpconnection during shutdown r=dragana
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 08 Feb 2016 17:21:43 -0500
changeset 283616 5864b1e738f62de17d17fd899c275b0006aec00d
parent 283615 22ef3a056e12c4956c5523917aa3c48713e4cb79
child 283617 b1c430b90f227fc7890dd39097203606225b8b01
push id29988
push usercbook@mozilla.com
push dateWed, 10 Feb 2016 10:47:59 +0000
treeherdermozilla-central@7042e8a19f94 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1246778
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1246778 - dont loop in nshttpconnection during shutdown r=dragana
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)
@@ -1785,17 +1785,17 @@ nsHttpConnection::OnSocketReadable()
                     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;