Bug 1451293 - P2: Call SetConnRefTaken r=michal
authorKershaw Chang <kershaw@mozilla.com>
Mon, 04 Feb 2019 08:42:11 +0000
changeset 456603 51df10abf1da898f73057f63bfb736c296ad9b8b
parent 456602 83f419699bf159a363b14930e1f26aec2a392b10
child 456604 9dc88ca66bfa8bf16f1cfd5af000bf06ff75245d
push id35496
push userbtara@mozilla.com
push dateMon, 04 Feb 2019 17:36:40 +0000
treeherdermozilla-central@be1beccfb86d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs1451293
milestone67.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 1451293 - P2: Call SetConnRefTaken r=michal In part1 patch[1], nsHttpTransaction::GetConnectionReference is removed in order to make sure single thread access to nsHttpTransaction::mConnection. Since we called mH2WSTransaction->SetConnRefTaken in nsHttpTransaction::GetConnectionReference, we need to find a new place to do this. This patch adds a new function nsHttpTransaction::SetH2WSConnRefTaken to call mH2WSTransaction->SetConnRefTaken. [1] https://phabricator.services.mozilla.com/D17221 Differential Revision: https://phabricator.services.mozilla.com/D17853
netwerk/protocol/http/nsHttpChannel.cpp
netwerk/protocol/http/nsHttpTransaction.cpp
netwerk/protocol/http/nsHttpTransaction.h
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -7501,16 +7501,20 @@ nsHttpChannel::OnStopRequest(nsIRequest 
         // a new request over such a half-stated connection.
         if (!mAuthConnectionRestartable) {
           LOG(("  not reusing a half-authenticated sticky connection"));
           transactionWithStickyConn->DontReuseConnection();
         }
       }
     }
 
+    if (mCaps & NS_HTTP_STICKY_CONNECTION) {
+      mTransaction->SetH2WSConnRefTaken();
+    }
+
     mTransferSize = mTransaction->GetTransferSize();
 
     // If we are using the transaction to serve content, we also save the
     // time since async open in the cache entry so we can compare telemetry
     // between cache and net response.
     // Do not store the time of conditional requests because even if we
     // fetch the data from the server, the time includes loading of the old
     // cache entry which would skew the network load time.
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -457,16 +457,26 @@ nsresult nsHttpTransaction::Init(
 }
 
 // This method should only be used on the socket thread
 nsAHttpConnection *nsHttpTransaction::Connection() {
   MOZ_ASSERT(OnSocketThread(), "not on socket thread");
   return mConnection.get();
 }
 
+void nsHttpTransaction::SetH2WSConnRefTaken() {
+  if (mH2WSTransaction) {
+    // Need to let the websocket transaction/connection know we've reached
+    // this point so it can stop forwarding information through us and
+    // instead communicate directly with the websocket channel.
+    mH2WSTransaction->SetConnRefTaken();
+    mH2WSTransaction = nullptr;
+  }
+}
+
 nsHttpResponseHead *nsHttpTransaction::TakeResponseHead() {
   MOZ_ASSERT(!mResponseHeadTaken, "TakeResponseHead called 2x");
 
   // Lock TakeResponseHead() against main thread
   MutexAutoLock lock(*nsHttp::GetLock());
 
   mResponseHeadTaken = true;
 
--- a/netwerk/protocol/http/nsHttpTransaction.h
+++ b/netwerk/protocol/http/nsHttpTransaction.h
@@ -106,16 +106,18 @@ class nsHttpTransaction final : public n
   // Called to take ownership of the response headers; the transaction
   // will drop any reference to the response headers after this call.
   nsHttpResponseHead *TakeResponseHead();
 
   // Called to take ownership of the trailer headers.
   // Returning null if there is no trailer.
   nsHttpHeaderArray *TakeResponseTrailers();
 
+  void SetH2WSConnRefTaken();
+
   // Called to set/find out if the transaction generated a complete response.
   bool ResponseIsComplete() { return mResponseIsComplete; }
   void SetResponseIsComplete() { mResponseIsComplete = true; }
 
   bool ProxyConnectFailed() { return mProxyConnectFailed; }
 
   void EnableKeepAlive() { mCaps |= NS_HTTP_ALLOW_KEEPALIVE; }
   void MakeSticky() { mCaps |= NS_HTTP_STICKY_CONNECTION; }