Bug 1537761 - P1: Send an IPC message for ClearHostMapping() r=dragana
authorKershaw Chang <kershaw@mozilla.com>
Tue, 10 Mar 2020 16:28:47 +0000
changeset 517875 457118de807cdddbcccba8294e988427ae3a1934
parent 517874 91c04bc7ec999933cecded74bf323f3a4e7d16c5
child 517876 ecc0db42db9cfe23698c0e2f726bd9bd4b409ea5
push id37203
push userccoroiu@mozilla.com
push dateWed, 11 Mar 2020 04:11:49 +0000
treeherdermozilla-central@884162af76f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1537761
milestone76.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 1537761 - P1: Send an IPC message for ClearHostMapping() r=dragana Differential Revision: https://phabricator.services.mozilla.com/D65552
netwerk/ipc/PSocketProcess.ipdl
netwerk/ipc/SocketProcessParent.cpp
netwerk/ipc/SocketProcessParent.h
netwerk/protocol/http/AltServiceChild.cpp
netwerk/protocol/http/AltServiceChild.h
netwerk/protocol/http/AltServiceParent.cpp
netwerk/protocol/http/AltServiceParent.h
netwerk/protocol/http/AlternateServices.cpp
netwerk/protocol/http/Http2Push.cpp
netwerk/protocol/http/HttpConnectionUDP.cpp
netwerk/protocol/http/HttpTrafficAnalyzer.cpp
netwerk/protocol/http/HttpTrafficAnalyzer.h
netwerk/protocol/http/HttpTransactionChild.cpp
netwerk/protocol/http/HttpTransactionParent.cpp
netwerk/protocol/http/HttpTransactionShell.h
netwerk/protocol/http/PAltService.ipdl
netwerk/protocol/http/moz.build
netwerk/protocol/http/nsHttpConnection.cpp
netwerk/protocol/http/nsHttpHandler.cpp
netwerk/protocol/http/nsHttpHandler.h
netwerk/protocol/http/nsHttpTransaction.cpp
--- a/netwerk/ipc/PSocketProcess.ipdl
+++ b/netwerk/ipc/PSocketProcess.ipdl
@@ -9,16 +9,17 @@ include protocol PProfiler;
 include protocol PWebrtcTCPSocket;
 include protocol PHttpTransaction;
 include protocol PHttpConnectionMgr;
 include protocol PFileDescriptorSet;
 include protocol PChildToParentStream;
 include protocol PParentToChildStream;
 include protocol PInputChannelThrottleQueue;
 include protocol PBackground;
+include protocol PAltService;
 
 include MemoryReportTypes;
 include NeckoChannelParams;
 include PBrowserOrId;
 include PrefsTypes;
 
 using mozilla::dom::NativeThreadId from "mozilla/dom/TabMessageUtils.h";
 using mozilla::Telemetry::HistogramAccumulation from "mozilla/TelemetryComms.h";
@@ -39,16 +40,17 @@ protocol PSocketProcess
   manages PDNSRequest;
   manages PWebrtcTCPSocket;
   manages PFileDescriptorSet;
   manages PHttpTransaction;
   manages PHttpConnectionMgr;
   manages PChildToParentStream;
   manages PParentToChildStream;
   manages PInputChannelThrottleQueue;
+  manages PAltService;
 
 parent:
   async InitCrashReporter(Shmem shmem, NativeThreadId threadId);
   async AddMemoryReport(MemoryReport aReport);
   async FinishMemoryReport(uint32_t aGeneration);
   // Messages for sending telemetry to parent process.
   async AccumulateChildHistograms(HistogramAccumulation[] accumulations);
   async AccumulateChildKeyedHistograms(KeyedHistogramAccumulation[] accumulations);
@@ -64,16 +66,17 @@ parent:
   async PChildToParentStream();
   async ObserveHttpActivity(HttpActivityArgs aActivityArgs,
                             uint32_t aActivityType,
                             uint32_t aActivitySubtype,
                             PRTime   aTimestamp,
                             uint64_t aExtraSizeData,
                             nsCString aExtraStringData);
   async InitBackground(Endpoint<PBackgroundParent> aEndpoint);
+  async PAltService();
 
 child:
   async PreferenceUpdate(Pref pref);
   async RequestMemoryReport(uint32_t generation,
                             bool anonymize,
                             bool minimizeMemoryUsage,
                             FileDescriptor? DMDFile);
   async SetOffline(bool offline);
--- a/netwerk/ipc/SocketProcessParent.cpp
+++ b/netwerk/ipc/SocketProcessParent.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "SocketProcessParent.h"
 #include "SocketProcessLogging.h"
 
+#include "AltServiceParent.h"
 #include "HttpTransactionParent.h"
 #include "SocketProcessHost.h"
 #include "mozilla/dom/MemoryReportRequest.h"
 #include "mozilla/ipc/FileDescriptorSetParent.h"
 #include "mozilla/ipc/IPCStreamAlloc.h"
 #include "mozilla/ipc/PChildToParentStreamParent.h"
 #include "mozilla/ipc/PParentToChildStreamParent.h"
 #include "mozilla/net/DNSRequestParent.h"
@@ -231,16 +232,22 @@ mozilla::ipc::IPCResult SocketProcessPar
   LOG(("SocketProcessParent::RecvInitBackground\n"));
   if (!ipc::BackgroundParent::Alloc(nullptr, std::move(aEndpoint))) {
     return IPC_FAIL(this, "BackgroundParent::Alloc failed");
   }
 
   return IPC_OK();
 }
 
+already_AddRefed<PAltServiceParent>
+SocketProcessParent::AllocPAltServiceParent() {
+  RefPtr<AltServiceParent> actor = new AltServiceParent();
+  return actor.forget();
+}
+
 // To ensure that IPDL is finished before SocketParent gets deleted.
 class DeferredDeleteSocketProcessParent : public Runnable {
  public:
   explicit DeferredDeleteSocketProcessParent(
       UniquePtr<SocketProcessParent>&& aParent)
       : Runnable("net::DeferredDeleteSocketProcessParent"),
         mParent(std::move(aParent)) {}
 
--- a/netwerk/ipc/SocketProcessParent.h
+++ b/netwerk/ipc/SocketProcessParent.h
@@ -92,16 +92,18 @@ class SocketProcessParent final
   mozilla::ipc::IPCResult RecvObserveHttpActivity(
       const HttpActivityArgs& aArgs, const uint32_t& aActivityType,
       const uint32_t& aActivitySubtype, const PRTime& aTimestamp,
       const uint64_t& aExtraSizeData, const nsCString& aExtraStringData);
 
   mozilla::ipc::IPCResult RecvInitBackground(
       Endpoint<PBackgroundParent>&& aEndpoint);
 
+  already_AddRefed<PAltServiceParent> AllocPAltServiceParent();
+
  private:
   SocketProcessHost* mHost;
   UniquePtr<dom::MemoryReportRequestHost> mMemoryReportRequest;
 
   static void Destroy(UniquePtr<SocketProcessParent>&& aParent);
 };
 
 }  // namespace net
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/AltServiceChild.cpp
@@ -0,0 +1,82 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim:set ts=4 sw=4 sts=4 et cin: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// HttpLog.h should generally be included first
+#include "HttpLog.h"
+
+#include "AltServiceChild.h"
+#include "mozilla/ClearOnShutdown.h"
+#include "mozilla/StaticPtr.h"
+#include "mozilla/net/SocketProcessChild.h"
+#include "nsHttpConnectionInfo.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
+namespace net {
+
+StaticRefPtr<AltServiceChild> sAltServiceChild;
+
+AltServiceChild::AltServiceChild() {
+  LOG(("AltServiceChild ctor [%p]\n", this));
+}
+
+AltServiceChild::~AltServiceChild() {
+  LOG(("AltServiceChild dtor [%p]\n", this));
+}
+
+// static
+bool AltServiceChild::EnsureAltServiceChild() {
+  MOZ_ASSERT(XRE_IsSocketProcess());
+  MOZ_ASSERT(NS_IsMainThread());
+
+  if (sAltServiceChild) {
+    return true;
+  }
+
+  SocketProcessChild* socketChild = SocketProcessChild::GetSingleton();
+  if (!socketChild || socketChild->IsShuttingDown()) {
+    return false;
+  }
+
+  sAltServiceChild = new AltServiceChild();
+  ClearOnShutdown(&sAltServiceChild);
+
+  if (!socketChild->SendPAltServiceConstructor(sAltServiceChild)) {
+    sAltServiceChild = nullptr;
+    return false;
+  }
+
+  return true;
+}
+
+void AltServiceChild::ClearHostMapping(nsHttpConnectionInfo* aCi) {
+  LOG(("AltServiceChild::ClearHostMapping ci=%s", aCi->HashKey().get()));
+  MOZ_ASSERT(aCi);
+
+  RefPtr<nsHttpConnectionInfo> ci = aCi->Clone();
+  auto task = [ci{std::move(ci)}]() {
+    if (!EnsureAltServiceChild()) {
+      return;
+    }
+
+    if (!ci->GetOrigin().IsEmpty() && sAltServiceChild->CanSend()) {
+      Unused << sAltServiceChild->SendClearHostMapping(
+          ci->GetOrigin(), ci->OriginPort(), ci->GetOriginAttributes(),
+          ci->GetTopWindowOrigin());
+    }
+  };
+
+  if (!NS_IsMainThread()) {
+    MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(NS_NewRunnableFunction(
+        "net::AltServiceChild::ClearHostMapping", task)));
+    return;
+  }
+
+  task();
+}
+
+}  // namespace net
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/AltServiceChild.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef AltServiceChild_h__
+#define AltServiceChild_h__
+
+#include "mozilla/net/PAltServiceChild.h"
+
+namespace mozilla {
+namespace net {
+
+class nsHttpConnectionInfo;
+
+class AltServiceChild final : public PAltServiceChild {
+ public:
+  NS_INLINE_DECL_REFCOUNTING(AltServiceChild, override)
+
+  static bool EnsureAltServiceChild();
+  static void ClearHostMapping(nsHttpConnectionInfo* aCi);
+
+ private:
+  AltServiceChild();
+  virtual ~AltServiceChild();
+};
+
+}  // namespace net
+}  // namespace mozilla
+
+#endif  // AltServiceChild_h__
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/AltServiceParent.cpp
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim:set ts=4 sw=4 sts=4 et cin: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// HttpLog.h should generally be included first
+#include "HttpLog.h"
+
+#include "AltServiceParent.h"
+#include "nsHttpHandler.h"
+
+namespace mozilla {
+namespace net {
+
+mozilla::ipc::IPCResult AltServiceParent::RecvClearHostMapping(
+    const nsCString& aHost, const int32_t& aPort,
+    const OriginAttributes& aOriginAttributes,
+    const nsCString& aTopWindowOrigin) {
+  LOG(("AltServiceParent::RecvClearHostMapping [this=%p]\n", this));
+  if (gHttpHandler) {
+    gHttpHandler->AltServiceCache()->ClearHostMapping(
+        aHost, aPort, aOriginAttributes, aTopWindowOrigin);
+  }
+  return IPC_OK();
+}
+
+void AltServiceParent::ActorDestroy(ActorDestroyReason aWhy) {
+  LOG(("AltServiceParent::ActorDestroy [this=%p]\n", this));
+}
+
+}  // namespace net
+}  // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/AltServiceParent.h
@@ -0,0 +1,33 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef AltServiceParent_h__
+#define AltServiceParent_h__
+
+#include "mozilla/net/PAltServiceParent.h"
+
+namespace mozilla {
+namespace net {
+
+class AltServiceParent final : public PAltServiceParent {
+ public:
+  NS_INLINE_DECL_REFCOUNTING(AltServiceParent, override)
+  AltServiceParent() = default;
+
+  mozilla::ipc::IPCResult RecvClearHostMapping(
+      const nsCString& aHost, const int32_t& aPort,
+      const OriginAttributes& aOriginAttributes,
+      const nsCString& aTopWindowOrigin);
+
+  void ActorDestroy(ActorDestroyReason aWhy) override;
+
+ private:
+  virtual ~AltServiceParent() = default;
+};
+
+}  // namespace net
+}  // namespace mozilla
+
+#endif  // AltServiceParent_h__
--- a/netwerk/protocol/http/AlternateServices.cpp
+++ b/netwerk/protocol/http/AlternateServices.cpp
@@ -1143,16 +1143,18 @@ class ProxyClearHostMapping : public Run
   int32_t mPort;
   OriginAttributes mOriginAttributes;
   nsCString mTopWindowOrigin;
 };
 
 void AltSvcCache::ClearHostMapping(const nsACString& host, int32_t port,
                                    const OriginAttributes& originAttributes,
                                    const nsACString& topWindowOrigin) {
+  MOZ_ASSERT(XRE_IsParentProcess());
+
   if (!NS_IsMainThread()) {
     nsCOMPtr<nsIRunnable> event = new ProxyClearHostMapping(
         host, port, originAttributes, topWindowOrigin);
     if (event) {
       NS_DispatchToMainThread(event);
     }
     return;
   }
--- a/netwerk/protocol/http/Http2Push.cpp
+++ b/netwerk/protocol/http/Http2Push.cpp
@@ -11,17 +11,21 @@
 #undef LOG
 #define LOG(args) LOG5(args)
 #undef LOG_ENABLED
 #define LOG_ENABLED() LOG5_ENABLED()
 
 #include <algorithm>
 
 #include "Http2Push.h"
+#include "nsHttpHandler.h"
+#include "nsHttpTransaction.h"
 #include "nsIHttpPushListener.h"
+#include "nsISocketTransport.h"
+#include "nsSocketTransportService2.h"
 #include "nsString.h"
 
 namespace mozilla {
 namespace net {
 
 // Because WeakPtr isn't thread-safe we must ensure that the object is destroyed
 // on the socket thread, so any Release() called on a different thread is
 // dispatched to the socket thread.
--- a/netwerk/protocol/http/HttpConnectionUDP.cpp
+++ b/netwerk/protocol/http/HttpConnectionUDP.cpp
@@ -218,17 +218,17 @@ void HttpConnectionUDP::Close(nsresult r
   }
 
   if (NS_FAILED(reason)) {
     // The connection and security errors clear out alt-svc mappings
     // in case any previously validated ones are now invalid
     if (((reason == NS_ERROR_NET_RESET) ||
          (NS_ERROR_GET_MODULE(reason) == NS_ERROR_MODULE_SECURITY)) &&
         mConnInfo && !(mTransactionCaps & NS_HTTP_ERROR_SOFTLY)) {
-      gHttpHandler->AltServiceCache()->ClearHostMapping(mConnInfo);
+      gHttpHandler->ClearHostMapping(mConnInfo);
     }
 
     if (mSocketTransport) {
       mSocketTransport->SetEventSink(nullptr, nullptr);
 
       // If there are bytes sitting in the input queue then read them
       // into a junk buffer to avoid generating a tcp rst by closing a
       // socket with data pending. TLS is a classic case of this where
--- a/netwerk/protocol/http/HttpTrafficAnalyzer.cpp
+++ b/netwerk/protocol/http/HttpTrafficAnalyzer.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "HttpTrafficAnalyzer.h"
 #include "HttpLog.h"
 
 #include "mozilla/StaticPrefs_network.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
+#include "nsSocketTransportService2.h"
 
 namespace mozilla {
 namespace net {
 
 NS_NAMED_LITERAL_CSTRING(kInvalidCategory, "INVALID_CATEGORY");
 
 #define DEFINE_CATEGORY(_name, _idx) NS_LITERAL_CSTRING("Y" #_idx "_" #_name),
 static const nsCString gKeyName[] = {
--- a/netwerk/protocol/http/HttpTrafficAnalyzer.h
+++ b/netwerk/protocol/http/HttpTrafficAnalyzer.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_netwerk_protocol_http_HttpTrafficAnalyzer_h
 #define mozilla_netwerk_protocol_http_HttpTrafficAnalyzer_h
 
+#include <stdint.h>
 #include "nsTArrayForwardDeclare.h"
 
 namespace mozilla {
 namespace net {
 
 #define DEFINE_CATEGORY(_name, _idx) e##_name = _idx##u,
 enum HttpTrafficCategory : uint8_t {
 #include "HttpTrafficAnalyzer.inc"
--- a/netwerk/protocol/http/HttpTransactionChild.cpp
+++ b/netwerk/protocol/http/HttpTransactionChild.cpp
@@ -11,16 +11,18 @@
 
 #include "mozilla/ipc/IPCStreamUtils.h"
 #include "mozilla/net/InputChannelThrottleQueueChild.h"
 #include "mozilla/net/SocketProcessChild.h"
 #include "nsInputStreamPump.h"
 #include "nsHttpHandler.h"
 #include "nsProxyInfo.h"
 #include "nsProxyRelease.h"
+#include "nsQueryObject.h"
+#include "nsSerializationHelper.h"
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ISUPPORTS(HttpTransactionChild, nsIRequestObserver, nsIStreamListener,
                   nsITransportEventSink, nsIThrottledInputChannel);
 
 //-----------------------------------------------------------------------------
--- a/netwerk/protocol/http/HttpTransactionParent.cpp
+++ b/netwerk/protocol/http/HttpTransactionParent.cpp
@@ -8,17 +8,20 @@
 #include "HttpLog.h"
 
 #include "HttpTransactionParent.h"
 #include "mozilla/ipc/IPCStreamUtils.h"
 #include "mozilla/net/InputChannelThrottleQueueParent.h"
 #include "mozilla/net/ChannelEventQueue.h"
 #include "mozilla/net/SocketProcessParent.h"
 #include "nsHttpHandler.h"
+#include "nsQueryObject.h"
+#include "nsSerializationHelper.h"
 #include "nsStreamUtils.h"
+#include "nsStringStream.h"
 
 namespace mozilla {
 namespace net {
 
 NS_IMPL_ADDREF(HttpTransactionParent)
 NS_INTERFACE_MAP_BEGIN(HttpTransactionParent)
   NS_INTERFACE_MAP_ENTRY(nsIRequest)
   NS_INTERFACE_MAP_ENTRY(nsIThreadRetargetableRequest)
--- a/netwerk/protocol/http/HttpTransactionShell.h
+++ b/netwerk/protocol/http/HttpTransactionShell.h
@@ -13,21 +13,21 @@
 #include "mozilla/UniquePtr.h"
 
 class nsIEventTraget;
 class nsIInputStream;
 class nsIInterfaceRequestor;
 class nsIRequest;
 class nsIRequestContext;
 class nsITransportEventSink;
-enum HttpTrafficCategory : uint8_t;
 
 namespace mozilla {
 namespace net {
 
+enum HttpTrafficCategory : uint8_t;
 class Http2PushedStreamWrapper;
 class HttpTransactionParent;
 class nsHttpConnectionInfo;
 class nsHttpHeaderArray;
 class nsHttpRequestHead;
 class nsHttpTransaction;
 class TransactionObserverResult;
 union NetAddr;
new file mode 100644
--- /dev/null
+++ b/netwerk/protocol/http/PAltService.ipdl
@@ -0,0 +1,28 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set sw=2 ts=8 et tw=80 : */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+include protocol PSocketProcess;
+
+using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
+
+namespace mozilla {
+namespace net {
+
+refcounted protocol PAltService
+{
+  manager PSocketProcess;
+
+parent:
+  async ClearHostMapping(nsCString host, int32_t port,
+                         OriginAttributes originAttributes,
+                         nsCString topWindowOrigin);
+
+child:
+  async __delete__();
+};
+
+} // namespace net
+} // namespace mozilla
--- a/netwerk/protocol/http/moz.build
+++ b/netwerk/protocol/http/moz.build
@@ -32,16 +32,18 @@ EXPORTS += [
     'nsHttpHeaderArray.h',
     'nsHttpRequestHead.h',
     'nsHttpResponseHead.h',
 ]
 
 EXPORTS.mozilla.net += [
     'AltDataOutputStreamChild.h',
     'AltDataOutputStreamParent.h',
+    'AltServiceChild.h',
+    'AltServiceParent.h',
     'BackgroundChannelRegistrar.h',
     'ClassifierDummyChannel.h',
     'ClassifierDummyChannelChild.h',
     'ClassifierDummyChannelParent.h',
     'HttpAuthUtils.h',
     'HttpBackgroundChannelChild.h',
     'HttpBackgroundChannelParent.h',
     'HttpBaseChannel.h',
@@ -65,16 +67,18 @@ EXPORTS.mozilla.net += [
 SOURCES += [
     'nsHttpChannelAuthProvider.cpp', # redefines GetAuthType
 ]
 
 UNIFIED_SOURCES += [
     'AltDataOutputStreamChild.cpp',
     'AltDataOutputStreamParent.cpp',
     'AlternateServices.cpp',
+    'AltServiceChild.cpp',
+    'AltServiceParent.cpp',
     'ASpdySession.cpp',
     'BackgroundChannelRegistrar.cpp',
     'CacheControlParser.cpp',
     'ClassifierDummyChannel.cpp',
     'ClassifierDummyChannelChild.cpp',
     'ClassifierDummyChannelParent.cpp',
     'ConnectionDiagnostics.cpp',
     'DelayHttpChannelQueue.cpp',
@@ -128,16 +132,17 @@ UNIFIED_SOURCES += [
 
 # These files cannot be built in unified mode because of OS X headers.
 SOURCES += [
     'nsHttpHandler.cpp',
 ]
 
 IPDL_SOURCES += [
     'PAltDataOutputStream.ipdl',
+    'PAltService.ipdl',
     'PClassifierDummyChannel.ipdl',
     'PHttpBackgroundChannel.ipdl',
     'PHttpChannel.ipdl',
     'PHttpConnectionMgr.ipdl',
     'PHttpTransaction.ipdl',
 ]
 
 include('/ipc/chromium/chromium-config.mozbuild')
--- a/netwerk/protocol/http/nsHttpConnection.cpp
+++ b/netwerk/protocol/http/nsHttpConnection.cpp
@@ -30,16 +30,17 @@
 #include "nsHttpRequestHead.h"
 #include "nsHttpResponseHead.h"
 #include "nsIClassOfService.h"
 #include "nsIOService.h"
 #include "nsISocketTransport.h"
 #include "nsSocketTransportService2.h"
 #include "nsISSLSocketControl.h"
 #include "nsISupportsPriority.h"
+#include "nsITransportSecurityInfo.h"
 #include "nsPreloadedStream.h"
 #include "nsProxyRelease.h"
 #include "nsSocketTransport2.h"
 #include "nsStringStream.h"
 #include "mozpkix/pkixnss.h"
 #include "sslt.h"
 #include "NSSErrorsService.h"
 #include "TunnelUtils.h"
@@ -1024,17 +1025,17 @@ void nsHttpConnection::Close(nsresult re
 
     mTLSFilter = nullptr;
 
     // The connection and security errors clear out alt-svc mappings
     // in case any previously validated ones are now invalid
     if (((reason == NS_ERROR_NET_RESET) ||
          (NS_ERROR_GET_MODULE(reason) == NS_ERROR_MODULE_SECURITY)) &&
         mConnInfo && !(mTransactionCaps & NS_HTTP_ERROR_SOFTLY)) {
-      gHttpHandler->AltServiceCache()->ClearHostMapping(mConnInfo);
+      gHttpHandler->ClearHostMapping(mConnInfo);
     }
 
     if (mSocketTransport) {
       mSocketTransport->SetEventSink(nullptr, nullptr);
 
       // If there are bytes sitting in the input queue then read them
       // into a junk buffer to avoid generating a tcp rst by closing a
       // socket with data pending. TLS is a classic case of this where
--- a/netwerk/protocol/http/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/nsHttpHandler.cpp
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // HttpLog.h should generally be included first
 #include "HttpLog.h"
 
 #include "prsystem.h"
 
+#include "AltServiceChild.h"
 #include "nsError.h"
 #include "nsHttp.h"
 #include "nsHttpHandler.h"
 #include "nsHttpChannel.h"
 #include "nsHttpAuthCache.h"
 #include "nsStandardURL.h"
 #include "LoadContextInfo.h"
 #include "nsCategoryManagerUtils.h"
@@ -2822,9 +2823,18 @@ nsresult nsHttpHandler::CompleteUpgrade(
   return mConnMgr->CompleteUpgrade(aTrans, aUpgradeListener);
 }
 
 nsresult nsHttpHandler::DoShiftReloadConnectionCleanup(
     nsHttpConnectionInfo* aCi) {
   return mConnMgr->DoShiftReloadConnectionCleanup(aCi);
 }
 
+void nsHttpHandler::ClearHostMapping(nsHttpConnectionInfo* aConnInfo) {
+  if (XRE_IsSocketProcess()) {
+    AltServiceChild::ClearHostMapping(aConnInfo);
+    return;
+  }
+
+  AltServiceCache()->ClearHostMapping(aConnInfo);
+}
+
 }  // namespace mozilla::net
--- a/netwerk/protocol/http/nsHttpHandler.h
+++ b/netwerk/protocol/http/nsHttpHandler.h
@@ -258,16 +258,18 @@ class nsHttpHandler final : public nsIHt
     return mConnMgr->AsHttpConnectionMgr();
   }
 
   AltSvcCache* AltServiceCache() const {
     MOZ_ASSERT(XRE_IsParentProcess());
     return mAltSvcCache.get();
   }
 
+  void ClearHostMapping(nsHttpConnectionInfo* aConnInfo);
+
   // cache support
   uint32_t GenerateUniqueID() { return ++mLastUniqueID; }
   uint32_t SessionStartTime() { return mSessionStartTime; }
 
   //
   // Connection management methods:
   //
   // - the handler only owns idle connections; it does not own active
--- a/netwerk/protocol/http/nsHttpTransaction.cpp
+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
@@ -1733,17 +1733,17 @@ nsresult nsHttpTransaction::HandleConten
       case 204:
       case 205:
       case 304:
         mNoContent = true;
         LOG(("this response should not contain a body.\n"));
         break;
       case 421:
         LOG(("Misdirected Request.\n"));
-        gHttpHandler->AltServiceCache()->ClearHostMapping(mConnInfo);
+        gHttpHandler->ClearHostMapping(mConnInfo);
         mCaps |= NS_HTTP_REFRESH_DNS;
 
         // retry on a new connection - just in case
         if (!mRestartCount) {
           mCaps &= ~NS_HTTP_ALLOW_KEEPALIVE;
           mForceRestart = true;  // force restart has built in loop protection
           return NS_ERROR_NET_RESET;
         }