Bug 766973: Don't allow synchronous DNS queries from the main thread. r=sworkman
authorJosh Aas <joshmoz@gmail.com>
Sat, 29 Sep 2012 00:50:59 -0400
changeset 114902 02a62c14ec3b5d72cd014422b7427c2e9b2e5012
parent 114901 bf8b676ae8d242cdf3feb83130f57c6dfdc5fa01
child 114903 68c4c30ff6f0a8ad3cd37a24dd3db452c24d9f3b
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssworkman
bugs766973
milestone18.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 766973: Don't allow synchronous DNS queries from the main thread. r=sworkman
netwerk/dns/nsDNSService2.cpp
netwerk/dns/nsIDNSService.idl
--- a/netwerk/dns/nsDNSService2.cpp
+++ b/netwerk/dns/nsDNSService2.cpp
@@ -682,16 +682,25 @@ nsDNSService::CancelAsyncResolve(const n
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDNSService::Resolve(const nsACString &hostname,
                       uint32_t          flags,
                       nsIDNSRecord    **result)
 {
+    NS_WARNING("Do not use synchronous DNS resolution! This API may be removed soon.");
+
+    // We will not allow this to be called on the main thread. This is transitional
+    // and a bit of a test for removing the synchronous API entirely.
+    if (NS_IsMainThread()) {
+        NS_ERROR("Synchronous DNS resolve failing - not allowed on the main thread!");
+        return NS_ERROR_FAILURE;
+    }
+
     // grab reference to global host resolver and IDN service.  beware
     // simultaneous shutdown!!
     nsRefPtr<nsHostResolver> res;
     nsCOMPtr<nsIIDNService> idn;
     bool localDomain = false;
     {
         MutexAutoLock lock(mLock);
         res = mResolver;
--- a/netwerk/dns/nsIDNSService.idl
+++ b/netwerk/dns/nsIDNSService.idl
@@ -54,19 +54,18 @@ interface nsIDNSService : nsISupports
      * @return An object that can be used to cancel the host lookup.
      */
     void cancelAsyncResolve(in AUTF8String       aHostName,
                             in unsigned long     aFlags,
                             in nsIDNSListener    aListener,
                             in nsresult          aReason);
     
     /**
-     * called to synchronously resolve a hostname.  warning this method may
-     * block the calling thread for a long period of time.  it is extremely
-     * unwise to call this function on the UI thread of an application.
+     * Called to synchronously resolve a hostname.  This method will fail
+     * if called from the main thread.
      *
      * @param aHostName
      *        the hostname or IP-address-literal to resolve.
      * @param aFlags
      *        a bitwise OR of the RESOLVE_ prefixed constants defined below.
      *
      * @return DNS record corresponding to the given hostname.
      * @throws NS_ERROR_UNKNOWN_HOST if host could not be resolved.