Bug 1188435 - Make TFO work with 0RTT and H2 work. r=mcmanus
authorDragana Damjanovic <dd.mozilla@gmail.com>
Thu, 04 May 2017 12:14:29 +0200
changeset 572780 8adfceab18a55dafa1f0b0d8f57f877c91da3e0c
parent 572779 033337b35af3ce70477bc53d70deaa0110e40d23
child 572781 e46c77c61346086e9ed145d337eb784c83858fb2
push id57195
push userbmo:rbarker@mozilla.com
push dateThu, 04 May 2017 20:08:56 +0000
reviewersmcmanus
bugs1188435
milestone55.0a1
Bug 1188435 - Make TFO work with 0RTT and H2 work. r=mcmanus
netwerk/protocol/http/nsHttpConnection.cpp
netwerk/protocol/http/nsHttpConnectionMgr.cpp
--- a/netwerk/protocol/http/nsHttpConnection.cpp
+++ b/netwerk/protocol/http/nsHttpConnection.cpp
@@ -2300,30 +2300,40 @@ nsHttpConnection::CheckForTraffic(bool c
         mTrafficStamp = false;
     }
 }
 
 nsAHttpTransaction *
 nsHttpConnection::CloseConnectionFastOpenTakesTooLongOrError()
 {
     MOZ_ASSERT(!mCurrentBytesRead);
+
+    RefPtr<nsAHttpTransaction> trans;
     if (mUsingSpdyVersion) {
+        // If we have a http2 connection just restart it as if 0rtt failed.
+        // For http2 we do not nee to do similar thing as for http1 because
+        // backup connection will pick immediately all this transaction anyway.
         DontReuse();
         mUsingSpdyVersion = 0;
+        if (mSpdySession) {
+            mSpdySession->Finish0RTT(true, true);
+        }
         mSpdySession = nullptr;
+    } else {
+        // For http1 we want to make this transaction an absolute priority to
+        // get the backup connection so we will return it from here.
+        if (NS_SUCCEEDED(mTransaction->RestartOnFastOpenError())) {
+            trans = mTransaction;
+        }
     }
 
     {
         MutexAutoLock lock(mCallbacksLock);
         mCallbacks = nullptr;
     }
 
-    RefPtr<nsAHttpTransaction> trans = nullptr;
-    if (NS_SUCCEEDED(mTransaction->RestartOnFastOpenError())) {
-        trans = mTransaction;
-    }
     mTransaction = nullptr;
     Close(NS_ERROR_NET_RESET);
     return trans;
 }
 
 } // namespace net
 } // namespace mozilla
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -3538,19 +3538,17 @@ nsHalfOpenSocket::FastOpenConnected(nsre
                (aError == NS_ERROR_NET_TIMEOUT)) {
         if (mEnt->mUseFastOpen) {
             gHttpHandler->IncrementFastOpenConsecutiveFailureCounter();
             mEnt->mUseFastOpen = false;
         }
         // This is called from nsSocketTransport::RecoverFromError. The
         // socket will try connect and we need to rewind nsHttpTransaction
         MOZ_ASSERT(mConnectionNegotiatingFastOpen);
-        DebugOnly<nsresult> rv =
-            mConnectionNegotiatingFastOpen->Transaction()->RestartOnFastOpenError();
-        MOZ_ASSERT(NS_SUCCEEDED(rv));
+        Unused << mConnectionNegotiatingFastOpen->Transaction()->RestartOnFastOpenError();
     }
     if (mConnectionNegotiatingFastOpen) {
         mSocketTransport = nullptr;
         mConnectionNegotiatingFastOpen = nullptr;
     }
 }
 
 void