Bug 1580740 - Don't use TRR when calling nsDNSService::DeprecatedSyncResolve on the main thread r=dragana
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 16 Dec 2019 12:33:57 +0000
changeset 507087 52e6fc030c2f9a9bf54d44dbade100644e5f3f41
parent 507086 f21621632fac449db8d93dbecc8a063f84550eef
child 507088 92e21dd89295b9abdb808574fbecc1055a7087f6
push id36922
push userncsoregi@mozilla.com
push dateMon, 16 Dec 2019 17:21:47 +0000
treeherdermozilla-central@27d0d6cc2131 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1580740
milestone73.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 1580740 - Don't use TRR when calling nsDNSService::DeprecatedSyncResolve on the main thread r=dragana `nsAuthSSPI` makes a call to `DeprecatedSyncResolve` that normally issues a DNS request and blocks until that completes. Apart from being a problem in general this is an issue when using TRR, because the HTTPS channel to the DoH server uses the main thread. When `DeprecatedSyncResolve` gets called on the main thread it then blocks the thread, and since the TRR request never has the chance to complete (even the TRR cancellation when the timer expires is processed on the main thread) the result is a deadlock. This structural problem should be fixed, but until that happens we should set the `RESOLVE_DISABLE_TRR` flag when calling `ResolveHost` from `nsDNSService::DeprecatedSyncResolve` Differential Revision: https://phabricator.services.mozilla.com/D57214
netwerk/dns/nsDNSService2.cpp
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -1073,16 +1073,24 @@ nsresult nsDNSService::ResolveInternal(
   PRMonitor* mon = PR_NewMonitor();
   if (!mon) return NS_ERROR_OUT_OF_MEMORY;
 
   PR_EnterMonitor(mon);
   RefPtr<nsDNSSyncRequest> syncReq = new nsDNSSyncRequest(mon);
 
   uint16_t af = GetAFForLookup(hostname, flags);
 
+  // TRR uses the main thread for the HTTPS channel to the DoH server.
+  // If this were to block the main thread while waiting for TRR it would
+  // likely cause a deadlock. Instead we intentionally choose to not use TRR
+  // for this.
+  if (NS_IsMainThread()) {
+    flags |= RESOLVE_DISABLE_TRR;
+  }
+
   rv = res->ResolveHost(hostname, RESOLVE_TYPE_DEFAULT, aOriginAttributes,
                         flags, af, syncReq);
   if (NS_SUCCEEDED(rv)) {
     // wait for result
     while (!syncReq->mDone) {
       PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
     }