From 756fb3e1455cd903f952ded1c45f86e3527875ed Mon Sep 17 00:00:00 2001
From: Nicholas Hurley <hurley@mozilla.com>
Date: Fri, 2 Feb 2018 11:03:08 -0800
Subject: Bug 1416529. r=mcmanus, a=ritu

MozReview-Commit-ID: CD1l5vLB4yy

--HG--
extra : rebase_source : d74f8ca96dab4e0d25d79948fcddbf8dab98bb36
---
 netwerk/protocol/http/Http2Session.cpp | 18 +++++++++---------
 netwerk/protocol/http/Http2Stream.cpp  | 14 ++++++++++++++
 netwerk/protocol/http/Http2Stream.h    |  1 +
 3 files changed, 24 insertions(+), 9 deletions(-)

(limited to 'netwerk/protocol/http')

diff --git a/netwerk/protocol/http/Http2Session.cpp b/netwerk/protocol/http/Http2Session.cpp
index 55ddbe908..4f350af83 100644
--- a/netwerk/protocol/http/Http2Session.cpp
+++ b/netwerk/protocol/http/Http2Session.cpp
@@ -1044,6 +1044,15 @@ Http2Session::CleanupStream(Http2Stream *aStream, nsresult aResult,
     return;
   }
 
+  Http2PushedStream *pushSource = aStream->PushSource();
+  if (pushSource) {
+    // aStream is a synthetic  attached to an even push
+    MOZ_ASSERT(pushSource->GetConsumerStream() == aStream);
+    MOZ_ASSERT(!aStream->StreamID());
+    MOZ_ASSERT(!(pushSource->StreamID() & 0x1));
+    aStream->ClearPushSource();
+  }
+
   if (aStream->DeferCleanup(aResult)) {
     LOG3(("Http2Session::CleanupStream 0x%X deferred\n", aStream->StreamID()));
     return;
@@ -1054,15 +1063,6 @@ Http2Session::CleanupStream(Http2Stream *aStream, nsresult aResult,
     return;
   }
 
-  Http2PushedStream *pushSource = aStream->PushSource();
-  if (pushSource) {
-    // aStream is a synthetic  attached to an even push
-    MOZ_ASSERT(pushSource->GetConsumerStream() == aStream);
-    MOZ_ASSERT(!aStream->StreamID());
-    MOZ_ASSERT(!(pushSource->StreamID() & 0x1));
-    pushSource->SetConsumerStream(nullptr);
-  }
-
   // don't reset a stream that has recevied a fin or rst
   if (!aStream->RecvdFin() && !aStream->RecvdReset() && aStream->StreamID() &&
       !(mInputFrameFinal && (aStream == mInputFrameDataStream))) { // !(recvdfin with mark pending)
diff --git a/netwerk/protocol/http/Http2Stream.cpp b/netwerk/protocol/http/Http2Stream.cpp
index f49c1f138..7a8f96855 100644
--- a/netwerk/protocol/http/Http2Stream.cpp
+++ b/netwerk/protocol/http/Http2Stream.cpp
@@ -103,10 +103,20 @@ Http2Stream::Http2Stream(nsAHttpTransaction *httpTransaction,
 
 Http2Stream::~Http2Stream()
 {
+  ClearPushSource();
   ClearTransactionsBlockedOnTunnel();
   mStreamID = Http2Session::kDeadStreamID;
 }
 
+void
+Http2Stream::ClearPushSource()
+{
+  if (mPushSource) {
+    mPushSource->SetConsumerStream(nullptr);
+    mPushSource = nullptr;
+  }
+}
+
 // ReadSegments() is used to write data down the socket. Generally, HTTP
 // request data is pulled from the approriate transaction and
 // converted to HTTP/2 data. Sometimes control data like a window-update is
@@ -1083,6 +1093,10 @@ Http2Stream::ConvertPushHeaders(Http2Decompressor *decompressor,
 void
 Http2Stream::Close(nsresult reason)
 {
+  // In case we are connected to a push, make sure the push knows we are closed,
+  // so it doesn't try to give us any more DATA that comes on it after our close.
+  ClearPushSource();
+
   mTransaction->Close(reason);
 }
 
diff --git a/netwerk/protocol/http/Http2Stream.h b/netwerk/protocol/http/Http2Stream.h
index 968461ee4..8783eefed 100644
--- a/netwerk/protocol/http/Http2Stream.h
+++ b/netwerk/protocol/http/Http2Stream.h
@@ -50,6 +50,7 @@ public:
 
   uint32_t StreamID() { return mStreamID; }
   Http2PushedStream *PushSource() { return mPushSource; }
+  void ClearPushSource();
 
   stateType HTTPState() { return mState; }
   void SetHTTPState(stateType val) { mState = val; }
-- 
cgit v1.2.3


From 8f7686bd7d4034c122ce050de9070e472952cf61 Mon Sep 17 00:00:00 2001
From: Valentin Gosu <valentin.gosu@gmail.com>
Date: Fri, 9 Feb 2018 13:20:04 +0100
Subject: Bug 1334465 - Make HttpChannelParent::mIPCClosed atomic. r=bagder,
 a=ritu

MozReview-Commit-ID: 6irCJMAjzjW

--HG--
extra : rebase_source : 2357ab0b9d1d693dac9e5f4f16f34f370c6591b5
extra : intermediate-source : 48b9f6671588c3c2b8d3b4ea6ba1267f5e297f83
extra : source : bd315ae86709c3459a3dbf0778022ff3b1908723
---
 netwerk/protocol/http/HttpChannelParent.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'netwerk/protocol/http')

diff --git a/netwerk/protocol/http/HttpChannelParent.h b/netwerk/protocol/http/HttpChannelParent.h
index 51fae5a82..a3b377d49 100644
--- a/netwerk/protocol/http/HttpChannelParent.h
+++ b/netwerk/protocol/http/HttpChannelParent.h
@@ -209,7 +209,7 @@ private:
   RefPtr<nsHttpChannel>       mChannel;
   nsCOMPtr<nsICacheEntry>       mCacheEntry;
   nsCOMPtr<nsIAssociatedContentSecurity>  mAssociatedContentSecurity;
-  bool mIPCClosed;                // PHttpChannel actor has been Closed()
+  Atomic<bool> mIPCClosed; // PHttpChannel actor has been Closed()
 
   nsCOMPtr<nsIChannel> mRedirectChannel;
   nsCOMPtr<nsIAsyncVerifyRedirectCallback> mRedirectCallback;
-- 
cgit v1.2.3


From 879619491f79870170abb0d398ab6a5c506984b0 Mon Sep 17 00:00:00 2001
From: Valentin Gosu <valentin.gosu@gmail.com>
Date: Sun, 11 Feb 2018 03:51:09 +0100
Subject: Bug 1334465 - Set mIPCClosed to true before calling SendDeleteSelf in
 order to avoid race. r=bagder, a=ritu

In the previous code, a race condition could cause us to call SendSetPriority() after calling SendDeleteSelf.

For example:
T1: SendDeleteSelf()
T2: if (!mIPCClosed) SendSetPriority()
T1: mIPCClosed = true

MozReview-Commit-ID: 3XOwCaphb2o

--HG--
extra : rebase_source : d6e6886402d1e0b0afed23c25a9fb18d8ca29ad6
extra : intermediate-source : cfc9afe916091e6449f7d748991e2a19187dc817
extra : source : 4ebdab0e332892378558817e30d0138c95199ce5
---
 netwerk/protocol/http/HttpChannelParent.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'netwerk/protocol/http')

diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp
index fe076a237..5f0859f28 100644
--- a/netwerk/protocol/http/HttpChannelParent.cpp
+++ b/netwerk/protocol/http/HttpChannelParent.cpp
@@ -1772,8 +1772,8 @@ HttpChannelParent::UpdateAndSerializeSecurityInfo(nsACString& aSerializedSecurit
 bool
 HttpChannelParent::DoSendDeleteSelf()
 {
-  bool rv = SendDeleteSelf();
   mIPCClosed = true;
+  bool rv = SendDeleteSelf();
   return rv;
 }
 
-- 
cgit v1.2.3


From 2d689a1bc3454e42a241724ad72007a5ee215742 Mon Sep 17 00:00:00 2001
From: Ben Kelly <ben@wanderview.com>
Date: Thu, 1 Mar 2018 07:37:31 -0800
Subject: Bug 1440775 - Make fetch API force-cache and only-if-cached use
 VALIDATE_NEVER instead of LOAD_FROM_CACHE. r=mayhemer, a=RyanVM

--HG--
extra : source : 60fb09de57ec145923da102f856399d3323f632b
extra : amend_source : b42db87defcc5615773cfa4659af9ff5b9cd4b72
extra : intermediate-source : 599641c7992def734cb352d9413aa51bf0e9793f
extra : histedit_source : 1d42c837225bdf000d3a68bef46a862be87d4044
---
 netwerk/protocol/http/HttpBaseChannel.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'netwerk/protocol/http')

diff --git a/netwerk/protocol/http/HttpBaseChannel.cpp b/netwerk/protocol/http/HttpBaseChannel.cpp
index 0ff792280..278c94db0 100644
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -2480,9 +2480,9 @@ HttpBaseChannel::GetFetchCacheMode(uint32_t* aFetchCacheMode)
     *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_RELOAD;
   } else if (mLoadFlags & VALIDATE_ALWAYS) {
     *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_CACHE;
-  } else if (mLoadFlags & (LOAD_FROM_CACHE | nsICachingChannel::LOAD_ONLY_FROM_CACHE)) {
+  } else if (mLoadFlags & (VALIDATE_NEVER | nsICachingChannel::LOAD_ONLY_FROM_CACHE)) {
     *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_ONLY_IF_CACHED;
-  } else if (mLoadFlags & LOAD_FROM_CACHE) {
+  } else if (mLoadFlags & VALIDATE_NEVER) {
     *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_FORCE_CACHE;
   } else {
     *aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_DEFAULT;
@@ -2518,7 +2518,7 @@ HttpBaseChannel::SetFetchCacheMode(uint32_t aFetchCacheMode)
     break;
   case nsIHttpChannelInternal::FETCH_CACHE_MODE_FORCE_CACHE:
     // force-cache means don't validate unless if the response would vary.
-    mLoadFlags |= LOAD_FROM_CACHE;
+    mLoadFlags |= VALIDATE_NEVER;
     break;
   case nsIHttpChannelInternal::FETCH_CACHE_MODE_ONLY_IF_CACHED:
     // only-if-cached means only from cache, no network, no validation, generate
@@ -2527,7 +2527,7 @@ HttpBaseChannel::SetFetchCacheMode(uint32_t aFetchCacheMode)
     // the user has things in their cache without any network traffic side
     // effects) are addressed in the Request constructor which enforces/requires
     // same-origin request mode.
-    mLoadFlags |= LOAD_FROM_CACHE | nsICachingChannel::LOAD_ONLY_FROM_CACHE;
+    mLoadFlags |= VALIDATE_NEVER | nsICachingChannel::LOAD_ONLY_FROM_CACHE;
     break;
   }
 
-- 
cgit v1.2.3