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 311298 0fee127a7175eac8b6d9a319243388f31eca7b23
parent 311297 5368758b59e9f0afb69290e799cd3d4a04c2f468
child 311299 98f615523e08a95bd0d318f3b09c39b4db2cd4a9
push id5637
push userkwierso@gmail.com
push dateThu, 18 Feb 2016 20:57:59 +0000
treeherdermozilla-beta@7619a19b83cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, sylvestre
bugs1246778
milestone45.0
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
@@ -1641,17 +1641,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
@@ -175,20 +175,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)
@@ -246,16 +246,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");
@@ -2026,16 +2027,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
@@ -472,28 +472,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;