Bug 957759 - Remove SRV experiment code (helps prevent crashes). r=mcmanus, a=lsblakk
authorNicholas Hurley <hurley@todesschaf.org>
Thu, 16 Jan 2014 10:30:01 -0500
changeset 175779 237a6c25de3926c42d508a4da6dc63c444305d64
parent 175778 2bb9442fd0c7e72b8f99e13d11346d152b0cbc24
child 175780 28995f30f8bbc47c2ae1822aa64b0beed8b67653
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, lsblakk
bugs957759
milestone28.0a2
Bug 957759 - Remove SRV experiment code (helps prevent crashes). r=mcmanus, a=lsblakk
modules/libpref/src/init/all.js
netwerk/dns/nsHostResolver.cpp
netwerk/dns/nsHostResolver.h
toolkit/components/telemetry/Histograms.json
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -959,21 +959,16 @@ pref("security.fileuri.strict_origin_pol
 //   pref("network.security.ports.banned", "1,2,3,4,5");
 // prevents necko connecting to ports 1-5 unless the protocol
 // overrides.
 
 // Allow necko to do A/B testing. Will generally only happen if
 // telemetry is also enabled as otherwise there is no way to report
 // the results
 pref("network.allow-experiments", true);
-#if defined(EARLY_BETA_OR_EARLIER)
-pref("network.dns.allow-srv-experiment", true);
-#else
-pref("network.dns.allow-srv-experiment", false);
-#endif
 
 // Transmit UDP busy-work to the LAN when anticipating low latency
 // network reads and on wifi to mitigate 802.11 Power Save Polling delays
 pref("network.tickle-wifi.enabled", false);
 pref("network.tickle-wifi.duration", 400);
 pref("network.tickle-wifi.delay", 16);
 
 // Turn off interprocess security checks. Needed to run xpcshell tests.
--- a/netwerk/dns/nsHostResolver.cpp
+++ b/netwerk/dns/nsHostResolver.cpp
@@ -30,20 +30,16 @@
 #include "plstr.h"
 #include "nsURLHelper.h"
 #include "nsThreadUtils.h"
 
 #include "mozilla/HashFunctions.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/VisualEventTracer.h"
-#if defined(XP_WIN)
-// See bug 942317 in case you're all "WTF, mate?!"
-#include "mozilla/Preferences.h"
-#endif
 
 using namespace mozilla;
 using namespace mozilla::net;
 
 //----------------------------------------------------------------------------
 
 // Use a persistent thread pool in order to avoid spinning up new threads all the time.
 // In particular, thread creation results in a res_init() call from libc which is 
@@ -424,23 +420,16 @@ nsHostResolver::nsHostResolver(uint32_t 
     , mLock("nsHostResolver.mLock")
     , mIdleThreadCV(mLock, "nsHostResolver.mIdleThreadCV")
     , mNumIdleThreads(0)
     , mThreadCount(0)
     , mActiveAnyThreadCount(0)
     , mEvictionQSize(0)
     , mPendingCount(0)
     , mShutdown(true)
-#if defined(XP_WIN)
-    // See bug 942317 in case you're all "WTF, mate?!"
-    , mExperimentLock("nsHostResolver.mExperimentLock")
-    , mHasRunExperiment(false)
-    , mNetworkExperimentsOK(true)
-    , mDnsExperimentOK(true)
-#endif
 {
     mCreationTime = PR_Now();
     PR_INIT_CLIST(&mHighQ);
     PR_INIT_CLIST(&mMediumQ);
     PR_INIT_CLIST(&mLowQ);
     PR_INIT_CLIST(&mEvictionQ);
 
     mLongIdleTimeout  = PR_SecondsToInterval(LongIdleTimeoutSeconds);
@@ -466,31 +455,16 @@ nsHostResolver::Init()
     // for the first nsHostResolver instance since that is usually created
     // during application startup.
     static int initCount = 0;
     if (initCount++ > 0) {
         LOG(("Calling 'res_ninit'.\n"));
         res_ninit(&_res);
     }
 #endif
-
-#if defined(XP_WIN)
-    // See bug 942317 in case you're all "WTF, mate?!"
-    Preferences::AddBoolVarCache(&mNetworkExperimentsOK,
-                                 "network.allow-experiments",
-                                 true);
-    Preferences::AddBoolVarCache(&mDnsExperimentOK,
-                                 "network.dns.allow-srv-experiment",
-#if defined(EARLY_BETA_OR_EARLIER)
-                                 true
-#else
-                                 false
-#endif
-                                );
-#endif
     return NS_OK;
 }
 
 void
 nsHostResolver::ClearPendingQueue(PRCList *aPendingQ)
 {
     // loop through pending queue, erroring out pending lookups.
     if (!PR_CLIST_IS_EMPTY(aPendingQ)) {
@@ -864,337 +838,21 @@ nsHostResolver::ConditionallyCreateThrea
     }
 #if defined(PR_LOGGING)
     else
       LOG(("  Unable to find a thread for looking up host [%s].\n", rec->host));
 #endif
     return NS_OK;
 }
 
-#if defined(XP_WIN)
-// See bug 942317 in case you're all "WTF, mate?!"
-#include "nsID.h"
-#include "nsIUUIDGenerator.h"
-#include "nsServiceManagerUtils.h"
-#include "prlink.h"
-#include "Windns.h"
-#include "Windows.h"
-
-typedef DNS_STATUS (__stdcall * DnsQueryFunc) (LPCSTR lpstrName, WORD wType,
-                                               DWORD Options, PVOID pExtra,
-                                               PDNS_RECORDA *ppQueryResultsSet,
-                                               PVOID *pReserved);
-
-class ExperimentFinishedRunner : public nsRunnable
-{
-public:
-    ExperimentFinishedRunner(nsIThread *thread)
-        :mThread(thread)
-    { }
-
-    ~ExperimentFinishedRunner()
-    { }
-
-    NS_IMETHOD Run() MOZ_OVERRIDE
-    {
-        mThread->Shutdown();
-        return NS_OK;
-    }
-
-private:
-    nsCOMPtr<nsIThread> mThread;
-};
-
-class ExperimentResolver : public nsRunnable
-{
-public:
-    ExperimentResolver(WORD queryType, nsACString &uuid, HANDLE *event,
-                       TimeStamp *start, TimeStamp *end, DNS_STATUS *status,
-                       DNS_RECORDA **results, DnsQueryFunc dnsQuery)
-        :mQueryType(queryType)
-        ,mUUID(uuid)
-        ,mEvent(event)
-        ,mStart(start)
-        ,mEnd(end)
-        ,mStatus(status)
-        ,mResults(results)
-        ,mDnsQuery(dnsQuery)
-    { }
-
-    ~ExperimentResolver()
-    { }
-
-    NS_IMETHOD Run() MOZ_OVERRIDE
-    {
-        nsAutoCString name;
-        if (mQueryType == DNS_TYPE_SRV) {
-            name.Assign(NS_LITERAL_CSTRING("_http2tls.srv-"));
-        } else {
-            name.Assign(NS_LITERAL_CSTRING("a-"));
-        }
-        name.Append(mUUID);
-        name.Append(NS_LITERAL_CSTRING(".http2test.mozilla.org"));
-
-        *mStart = mozilla::TimeStamp::Now();
-        *mStatus = mDnsQuery(name.get(), mQueryType, DNS_QUERY_STANDARD,
-                             nullptr, mResults, nullptr);
-        *mEnd = mozilla::TimeStamp::Now();
-
-        SetEvent(*mEvent);
-
-        return NS_OK;
-    }
-
-private:
-    WORD mQueryType;
-    nsAutoCString mUUID;
-    HANDLE *mEvent;
-    TimeStamp *mStart;
-    TimeStamp *mEnd;
-    DNS_STATUS *mStatus;
-    DNS_RECORDA **mResults;
-    DnsQueryFunc mDnsQuery;
-};
-
-class ExperimentRunner : public nsRunnable
-{
-public:
-    ExperimentRunner(nsIThread *experimentThread, nsIThread *resolveAThread,
-                     nsIThread *resolveSRVThread)
-        :mExperimentThread(experimentThread)
-        ,mResolveAThread(resolveAThread)
-        ,mResolveSRVThread(resolveSRVThread)
-    { }
-
-    ~ExperimentRunner()
-    { }
-
-    NS_IMETHOD Run() MOZ_OVERRIDE
-    {
-        // These are all declared here because compiler warnings about goto.
-        DnsQueryFunc dnsQuery;
-        TimeStamp startALookup, endALookup, startSRVLookup, endSRVLookup;
-        DNS_RECORDA *aResults, *srvResults;
-        DNS_STATUS aStatus, srvStatus;
-        int32_t experimentStatus;
-        Telemetry::ID deltaKey;
-        TimeDuration duration;
-        double delta;
-        uint32_t timeDelta;
-        nsresult rv;
-        nsID id;
-        char uuid[NSID_LENGTH];
-        nsAutoCString dnsUUID;
-        nsCOMPtr<nsIUUIDGenerator> uuidgen;
-        HANDLE events[2];
-        bool correctA = true, correctSRV = true;
-
-        PRLibrary *lib = PR_LoadLibrary("Dnsapi.dll");
-        if (!lib) {
-            goto out;
-        }
-
-        dnsQuery = (DnsQueryFunc) PR_FindFunctionSymbol(lib, "DnsQuery_A");
-        if (!dnsQuery) {
-            goto library_cleanup;
-        }
-
-        // Generate hostnames that are subhosts of aus.mozilla.org, as we want
-        // to make sure that whatever hostname we lookup will not be cached
-        // anywhere. Use separate names for the A and SRV lookups to ensure that
-        // Windows doesn't do any odd caching of NXDOMAIN in case the A lookup
-        // fails.
-        uuidgen = do_GetService("@mozilla.org/uuid-generator;1", &rv);
-        if (NS_FAILED(rv)) {
-            goto library_cleanup;
-        }
-        rv = uuidgen->GenerateUUIDInPlace(&id);
-        NS_ENSURE_SUCCESS(rv, NS_OK);
-        id.ToProvidedString(uuid);
-        // Strip off the { and } surrounding the UUID string
-        dnsUUID.Assign(Substring(nsDependentCString(uuid), 1, NSID_LENGTH - 3));
-
-        // Create events for A and SRV resolvers
-        events[0] = CreateEvent(NULL, TRUE, FALSE, TEXT("FinishedA"));
-        if (!events[0]) {
-            goto library_cleanup;
-        }
-
-        events[1] = CreateEvent(NULL, TRUE, FALSE, TEXT("FinishedSRV"));
-        if (!events[1]) {
-            goto aevent_cleanup;
-        }
-
-        // dispatch A resolver
-        mResolveAThread->Dispatch(new ExperimentResolver(DNS_TYPE_A,
-                                                         dnsUUID,
-                                                         &events[0],
-                                                         &startALookup,
-                                                         &endALookup,
-                                                         &aStatus,
-                                                         &aResults,
-                                                         dnsQuery),
-                                  NS_DISPATCH_NORMAL);
-
-        // dispatch SRV resolver
-        mResolveSRVThread->Dispatch(new ExperimentResolver(DNS_TYPE_SRV,
-                                                           dnsUUID,
-                                                           &events[1],
-                                                           &startSRVLookup,
-                                                           &endSRVLookup,
-                                                           &srvStatus,
-                                                           &srvResults,
-                                                           dnsQuery),
-                                    NS_DISPATCH_NORMAL);
-
-        WaitForMultipleObjects(2, events, TRUE, INFINITE);
-
-        // Ensure we got the expected results
-        if (aStatus == DNS_RCODE_NOERROR) {
-            if (aResults->Data.A.IpAddress != 0x7F000001) {
-                correctA = false;
-            }
-        }
-
-        if (srvStatus == DNS_RCODE_NOERROR) {
-            DNS_SRV_DATAA *srvData = &srvResults->Data.Srv;
-            if (_stricmp(srvData->pNameTarget, "success.http2test.mozilla.org") ||
-                srvData->wPort != 443 ||
-                srvData->wPriority != 100 ||
-                srvData->wWeight != 100) {
-                correctSRV = false;
-            }
-        }
-
-        if (aStatus == DNS_RCODE_NOERROR && srvStatus == DNS_RCODE_NOERROR) {
-            experimentStatus = kBothSucceed;
-            deltaKey = Telemetry::SRV_EXPERIMENT_SUCCESS_DELTA;
-            Telemetry::Accumulate(Telemetry::SRV_EXPERIMENT_A_CORRECT, correctA);
-            Telemetry::Accumulate(Telemetry::SRV_EXPERIMENT_SRV_CORRECT, correctSRV);
-        } else if (aStatus == DNS_RCODE_NOERROR) {
-            experimentStatus = kSRVFail;
-            deltaKey = Telemetry::SRV_EXPERIMENT_SRV_FAIL_DELTA;
-            Telemetry::Accumulate(Telemetry::SRV_EXPERIMENT_SRV_CORRECT, correctSRV);
-        } else if (srvStatus == DNS_RCODE_NOERROR) {
-            experimentStatus = kAFail;
-            deltaKey = Telemetry::SRV_EXPERIMENT_A_FAIL_DELTA;
-            Telemetry::Accumulate(Telemetry::SRV_EXPERIMENT_A_CORRECT, correctA);
-        } else { // aStatus != DNS_RCODE_NOERROR && srvStatus != DNS_RCODE_NOERROR
-            experimentStatus = kBothFail;
-            deltaKey = Telemetry::SRV_EXPERIMENT_FAIL_DELTA;
-            // Neither one succeeded, so our correctness flags are irrelevant
-        }
-
-        Telemetry::Accumulate(Telemetry::SRV_EXPERIMENT_STATUS,
-                              experimentStatus);
-        Telemetry::AccumulateTimeDelta(Telemetry::SRV_EXPERIMENT_SRV_TIME,
-                                       startSRVLookup, endSRVLookup);
-        Telemetry::AccumulateTimeDelta(Telemetry::SRV_EXPERIMENT_A_TIME,
-                                       startALookup, endALookup);
-
-        // Calculate time delta in ms clamped to [0, 2000] where 1000 means both
-        // lookups took the same amount of time, 0-999 means the SRV record came
-        // back faster, and 1001-2000 means the A record came back faster.
-        duration = (endALookup - startALookup) - (endSRVLookup - startSRVLookup);
-        delta = duration.ToMilliseconds();
-        if (delta < -1000.0) {
-            delta = -1000.0;
-        } else if (delta > 1000.0) {
-            delta = 1000.0;
-        }
-
-        timeDelta = static_cast<uint32_t>(delta) + 1000;
-        Telemetry::Accumulate(deltaKey, timeDelta);
-
-        mResolveSRVThread->Shutdown();
-        mResolveAThread->Shutdown();
-        CloseHandle(events[1]);
-aevent_cleanup:
-        CloseHandle(events[0]);
-        // Do the library cleanup here to avoid doing I/O on the main thread
-library_cleanup:
-        dnsQuery = nullptr;
-        PR_UnloadLibrary(lib);
-out:
-        NS_DispatchToMainThread(new ExperimentFinishedRunner(mExperimentThread));
-
-        return NS_OK;
-    }
-
-private:
-    nsCOMPtr<nsIThread> mExperimentThread;
-    nsCOMPtr<nsIThread> mResolveAThread;
-    nsCOMPtr<nsIThread> mResolveSRVThread;
-    static const uint32_t kBothSucceed = 0;
-    static const uint32_t kSRVFail = 1;
-    static const uint32_t kAFail = 2;
-    static const uint32_t kBothFail = 3;
-};
-
-void
-nsHostResolver::RunExperiment()
-{
-    if (!NS_IsMainThread()) {
-        return;
-    }
-
-    {
-        MutexAutoLock lock(mExperimentLock);
-        if (mHasRunExperiment) {
-            return;
-        }
-
-        mHasRunExperiment = true;
-    }
-
-    nsCOMPtr<nsIThread> experimentThread;
-    NS_NewNamedThread("SRV Experiment", getter_AddRefs(experimentThread));
-    if (!experimentThread) {
-        return;
-    }
-
-    // Create threads for A and SRV resolvers
-    nsCOMPtr<nsIThread> resolveAThread;
-    NS_NewNamedThread("Experiment A", getter_AddRefs(resolveAThread));
-    if (!resolveAThread) {
-        experimentThread->Shutdown();
-        return;
-    }
-
-    nsCOMPtr<nsIThread> resolveSRVThread;
-    NS_NewNamedThread("Experiment SRV", getter_AddRefs(resolveSRVThread));
-    if (!resolveSRVThread) {
-        resolveAThread->Shutdown();
-        experimentThread->Shutdown();
-        return;
-    }
-
-    experimentThread->Dispatch(new ExperimentRunner(experimentThread,
-                                                    resolveAThread,
-                                                    resolveSRVThread),
-                               NS_DISPATCH_NORMAL);
-}
-#endif
-
 nsresult
 nsHostResolver::IssueLookup(nsHostRecord *rec)
 {
     MOZ_EVENT_TRACER_WAIT(rec, "net::dns::resolve");
 
-#if defined(XP_WIN)
-    // See bug 942317 in case you're all "WTF, mate?!"
-    if (mNetworkExperimentsOK && mDnsExperimentOK && Telemetry::CanRecord() &&
-        !mHasRunExperiment) {
-        int offset = strlen(rec->host) - strlen(".mozilla.org");
-        if ((offset > 0) && (_stricmp(rec->host + offset, ".mozilla.org") == 0)) {
-            RunExperiment();
-        }
-    }
-#endif
-
     nsresult rv = NS_OK;
     NS_ASSERTION(!rec->resolving, "record is already being resolved");
 
     // Add rec to one of the pending queues, possibly removing it from mEvictionQ.
     // If rec is on mEvictionQ, then we can just move the owning
     // reference over to the new active queue.
     if (rec->next == rec)
         NS_ADDREF(rec);
--- a/netwerk/dns/nsHostResolver.h
+++ b/netwerk/dns/nsHostResolver.h
@@ -286,25 +286,16 @@ private:
     PRCList       mEvictionQ;
     uint32_t      mEvictionQSize;
     uint32_t      mPendingCount;
     PRTime        mCreationTime;
     bool          mShutdown;
     PRIntervalTime mLongIdleTimeout;
     PRIntervalTime mShortIdleTimeout;
 
-#if defined(XP_WIN)
-    // See bug 942317 in case you're all "WTF, mate?!"
-    void RunExperiment();
-    Mutex mExperimentLock;
-    bool mHasRunExperiment;
-    bool mNetworkExperimentsOK;
-    bool mDnsExperimentOK;
-#endif
-
 public:
     /*
      * Called by the networking dashboard via the DnsService2
      */
     void GetDNSCacheEntries(nsTArray<mozilla::net::DNSCacheEntries> *);
 };
 
 #endif // nsHostResolver_h__
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -1734,67 +1734,16 @@
     "n_buckets": 50,
     "description": "Time spent waiting on the cache service lock (ms) on the main thread in NSASYNCDOOMEVENT_RUN"
   },
   "DNT_USAGE": {
     "kind": "enumerated",
     "n_values": 3,
     "description": "I want to be tracked, I do NOT want to be tracked, DNT unset"
   },
-  "SRV_EXPERIMENT_SUCCESS_DELTA": {
-      "kind": "linear",
-      "high": "2000",
-      "n_buckets": 200,
-      "description": "Time delta between A and SRV records when both succeed. This (srv time in ms - a time in ms) + 1000."
-  },
-  "SRV_EXPERIMENT_SRV_FAIL_DELTA": {
-      "kind": "linear",
-      "high": "2000",
-      "n_buckets": 200,
-      "description": "Time delta between A and SRV records when SRV only fails. This (srv time in ms - a time in ms) + 1000."
-  },
-  "SRV_EXPERIMENT_A_FAIL_DELTA": {
-      "kind": "linear",
-      "high": "2000",
-      "n_buckets": 200,
-      "description": "Time delta between A and SRV records when A only fails. This (srv time in ms - a time in ms) + 1000."
-  },
-  "SRV_EXPERIMENT_FAIL_DELTA": {
-      "kind": "linear",
-      "high": "2000",
-      "n_buckets": 200,
-      "description": "Time delta between A and SRV records when both fail. This (srv time in ms - a time in ms) + 1000."
-  },
-  "SRV_EXPERIMENT_STATUS": {
-      "kind": "enumerated",
-      "n_values": 4,
-      "description": "Status of SRV experiment (0 - both OK, 1 - SRV fail, 2 - A fail, 3 - both fail)"
-  },
-  "SRV_EXPERIMENT_SRV_TIME": {
-      "kind": "exponential",
-      "high": "60000",
-      "n_buckets": 50,
-      "extended_statistics_ok": true,
-      "description": "How long (in ms) it took to get a result for a SRV record"
-  },
-  "SRV_EXPERIMENT_A_TIME": {
-      "kind": "exponential",
-      "high": "60000",
-      "n_buckets": 50,
-      "extended_statistics_ok": true,
-      "description": "How long (in ms) it took to get a result for an A record"
-  },
-  "SRV_EXPERIMENT_A_CORRECT": {
-      "kind": "boolean",
-      "description": "Whether a successful A query returned the results we expected"
-  },
-  "SRV_EXPERIMENT_SRV_CORRECT": {
-      "kind": "boolean",
-      "description": "Whether a successful SRV query returned the results we expected"
-  },
   "DNS_LOOKUP_METHOD2": {
     "kind": "enumerated",
     "n_values": 16,
     "description": "DNS Lookup Type (hit, renewal, negative-hit, literal, overflow, network-first, network-shared)"
   },
   "DNS_CLEANUP_AGE": {
     "kind": "exponential",
     "high": "1440",