Bug 1489229 - Return early from WPAD runnable when pref has been changed r=bagder
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 04 Oct 2018 08:42:21 +0000
changeset 439538 cc56daee035f30628eb6b56706ea7b5fb8ede0ff
parent 439537 2f1229c179d303c2df8c4fa7b05d7a4662f73422
child 439539 ff0aee3fd2ae32e5fb88ebd4636988b717c5d9c4
push id34778
push usernbeleuzu@mozilla.com
push dateThu, 04 Oct 2018 15:22:02 +0000
treeherdermozilla-central@01634947caab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbagder
bugs1489229, 356831
milestone64.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 1489229 - Return early from WPAD runnable when pref has been changed r=bagder Bug 356831 added a release assert that when performing WPAD the network.proxy.type pref is always 4 (PROXYCONFIG_WPAD). However, when changing the pref, the runnable is scheduled to run before the PAC thread is shutdown, so it will see the pref that is not PROXYCONFIG_WPAD, while attempting to do WPAD. To avoid this situation, we simply exit early when we detect the wrong pref value. Differential Revision: https://phabricator.services.mozilla.com/D7617
netwerk/base/nsPACMan.cpp
--- a/netwerk/base/nsPACMan.cpp
+++ b/netwerk/base/nsPACMan.cpp
@@ -90,17 +90,17 @@ GetNetworkProxyTypeFromPref(int32_t* typ
   *type = 0;
   nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
 
   if (!prefs) {
     LOG(("Failed to get a preference service object"));
     return NS_ERROR_FACTORY_NOT_REGISTERED;
   }
   nsresult rv = prefs->GetIntPref("network.proxy.type", type);
-  if (!NS_SUCCEEDED(rv)) {
+  if (NS_FAILED(rv)) {
     LOG(("Failed to retrieve network.proxy.type from prefs"));
     return rv;
   }
   LOG(("network.proxy.type pref retrieved: %d\n", *type));
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
@@ -559,18 +559,21 @@ nsPACMan::LoadPACFromURI(const nsACStrin
 
   // if we're on the main thread here so we can get hold of prefs,
   // we check that we have WPAD preffed on if we're auto-detecting
   if (mAutoDetect && NS_IsMainThread()) {
     nsresult rv = GetNetworkProxyTypeFromPref(&mProxyConfigType);
     if (NS_FAILED(rv)) {
       return rv;
     }
-    MOZ_RELEASE_ASSERT(mProxyConfigType == nsIProtocolProxyService::PROXYCONFIG_WPAD,
-            "WPAD is being executed when not selected by user");
+    if (mProxyConfigType != nsIProtocolProxyService::PROXYCONFIG_WPAD) {
+      LOG(("LoadPACFromURI - Aborting WPAD autodetection because the pref "
+           "doesn't match anymore"));
+      return NS_BINDING_ABORTED;
+    }
   }
   // Since we might get called from nsProtocolProxyService::Init, we need to
   // post an event back to the main thread before we try to use the IO service.
   //
   // But, we need to flag ourselves as loading, so that we queue up any PAC
   // queries the enter between now and when we actually load the PAC file.
 
   if (!mLoadPending) {
@@ -605,18 +608,21 @@ nsPACMan::GetPACFromDHCP(nsACString &aSp
   return rv;
 }
 
 nsresult
 nsPACMan::ConfigureWPAD(nsACString &aSpec)
 {
   MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
 
-  MOZ_RELEASE_ASSERT(mProxyConfigType == nsIProtocolProxyService::PROXYCONFIG_WPAD,
-            "WPAD is being executed when not selected by user");
+  if (mProxyConfigType != nsIProtocolProxyService::PROXYCONFIG_WPAD) {
+    LOG(("ConfigureWPAD - Aborting WPAD autodetection because the pref "
+         "doesn't match anymore"));
+    return NS_BINDING_ABORTED;
+  }
 
   aSpec.Truncate();
   if (mWPADOverDHCPEnabled) {
     GetPACFromDHCP(aSpec);
   }
 
   if (aSpec.IsEmpty()) {
     // We diverge from the WPAD spec here in that we don't walk the
@@ -646,17 +652,17 @@ nsPACMan::StartLoading()
   // CancelExistingLoad was called...
   if (!mLoader) {
     PostCancelPendingQ(NS_ERROR_ABORT);
     return;
   }
 
   if (mAutoDetect) {
     nsresult rv = GetNetworkProxyTypeFromPref(&mProxyConfigType);
-    if (!NS_SUCCEEDED(rv)) {
+    if (NS_FAILED(rv)) {
       NS_WARNING("Could not retrieve Network Proxy Type pref when auto-detecting proxy. Halting.");
       return;
     }
     RefPtr<ExecutePACThreadAction> wpadConfigurer =
       new ExecutePACThreadAction(this);
     wpadConfigurer->ConfigureWPAD();
     DispatchToPAC(wpadConfigurer.forget());
   } else {