Bug 1352273 - Restart the TFO failure counter if a captive portal is detected.r=mcmanus
authorDragana Damjanovic dd.mozilla@gmail.com
Fri, 19 May 2017 13:16:08 +0200
changeset 359107 2d38863c19d5fb0e0a0917e690e4fe360637f6a9
parent 359106 af622640b17f6101ecda4ee6f5deb9ea0963819c
child 359108 6f7809bc8778bb4c660e857fe450b583d048f956
push id90470
push userdd.mozilla@gmail.com
push dateFri, 19 May 2017 11:16:43 +0000
treeherdermozilla-inbound@2d38863c19d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1352273
milestone55.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 1352273 - Restart the TFO failure counter if a captive portal is detected.r=mcmanus
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -476,16 +476,21 @@ nsHttpHandler::Init()
         obsService->AddObserver(this, "last-pb-context-exited", true);
         obsService->AddObserver(this, "browser:purge-session-history", true);
         obsService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
         obsService->AddObserver(this, "application-background", true);
         obsService->AddObserver(this,
                                 "net:current-toplevel-outer-content-windowid",
                                 true);
 
+        if (mFastOpenSupported) {
+            obsService->AddObserver(this, "captive-portal-login", true);
+            obsService->AddObserver(this, "captive-portal-login-success", true);
+        }
+
         // disabled as its a nop right now
         // obsService->AddObserver(this, "net:failed-to-process-uri-content", true);
     }
 
     MakeNewRequestTokenBucket();
     mWifiTickler = new Tickler();
     if (NS_FAILED(mWifiTickler->Init()))
         mWifiTickler = nullptr;
@@ -643,17 +648,16 @@ nsHttpHandler::IncrementFastOpenConsecut
     LOG(("nsHttpHandler::IncrementFastOpenConsecutiveFailureCounter - "
          "failed=%d failure_limit=%d", mFastOpenConsecutiveFailureCounter,
          mFastOpenConsecutiveFailureLimit));
     if (mFastOpenConsecutiveFailureCounter < mFastOpenConsecutiveFailureLimit) {
         mFastOpenConsecutiveFailureCounter++;
         if (mFastOpenConsecutiveFailureCounter == mFastOpenConsecutiveFailureLimit) {
             LOG(("nsHttpHandler::IncrementFastOpenConsecutiveFailureCounter - "
                  "Fast open failed too many times"));
-            SetFastOpenNotSupported();
         }
     }
 }
 
 nsresult
 nsHttpHandler::GetStreamConverterService(nsIStreamConverterService **result)
 {
     if (!mStreamConvSvc) {
@@ -2310,16 +2314,21 @@ nsHttpHandler::Observe(nsISupports *subj
             if (sCurrentTopLevelOuterContentWindowId != windowId) {
                 sCurrentTopLevelOuterContentWindowId = windowId;
                 if (mConnMgr) {
                     mConnMgr->UpdateCurrentTopLevelOuterContentWindowId(
                         sCurrentTopLevelOuterContentWindowId);
                 }
             }
         }
+    } else if (!strcmp(topic, "captive-portal-login") ||
+               !strcmp(topic, "captive-portal-login-success")) {
+         // We have detected a captive portal and we will reset the Fast Open
+         // failure counter.
+         ResetFastOpenConsecutiveFailureCounter();
     }
 
     return NS_OK;
 }
 
 // nsISpeculativeConnect
 
 nsresult
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -159,17 +159,21 @@ public:
       return mTCPKeepaliveLongLivedEnabled;
     }
     // Returns time (secs) before first TCP keepalive probes should be sent;
     // same time used between successful keepalive probes.
     int32_t GetTCPKeepaliveLongLivedIdleTime() {
       return mTCPKeepaliveLongLivedIdleTimeS;
     }
 
-    bool UseFastOpen() { return mUseFastOpen && mFastOpenSupported; }
+    bool UseFastOpen()
+    {
+        return mUseFastOpen && mFastOpenSupported &&
+               mFastOpenConsecutiveFailureCounter < mFastOpenConsecutiveFailureLimit;
+    }
     // If one of tcp connections return PR_NOT_TCP_SOCKET_ERROR while trying
     // fast open, it means that Fast Open is turned off so we will not try again
     // until a restart. This is only on Linux.
     // For windows 10 we can only check whether a version of windows support
     // Fast Open at run time, so if we get error PR_NOT_IMPLEMENTED_ERROR it
     // means that Fast Open is not supported and we will set mFastOpenSupported
     // to false.
     void SetFastOpenNotSupported() { mFastOpenSupported = false; }