diff --git a/netwerk/ipc/PSocketProcess.ipdl b/netwerk/ipc/PSocketProcess.ipdl index aac991d06bd2..2ed4fd6b9a4f 100644 --- a/netwerk/ipc/PSocketProcess.ipdl +++ b/netwerk/ipc/PSocketProcess.ipdl @@ -134,6 +134,8 @@ parent: returns (bool aAccepted); async ODoHServiceActivated(bool aActivated); + async ExcludeHttp2OrHttp3(HttpConnectionInfoCloneArgs aArgs); + child: async Init(SocketPorcessInitAttributes aAttributes); async PreferenceUpdate(Pref pref); diff --git a/netwerk/ipc/SocketProcessParent.cpp b/netwerk/ipc/SocketProcessParent.cpp index 4d4df5da082d..108e064e17bb 100644 --- a/netwerk/ipc/SocketProcessParent.cpp +++ b/netwerk/ipc/SocketProcessParent.cpp @@ -439,5 +439,22 @@ mozilla::ipc::IPCResult SocketProcessParent::RecvODoHServiceActivated( return IPC_OK(); } +mozilla::ipc::IPCResult SocketProcessParent::RecvExcludeHttp2OrHttp3( + const HttpConnectionInfoCloneArgs& aArgs) { + RefPtr cinfo = + nsHttpConnectionInfo::DeserializeHttpConnectionInfoCloneArgs(aArgs); + if (!cinfo) { + MOZ_ASSERT(false, "failed to deserizlize http connection info"); + return IPC_OK(); + } + + if (cinfo->IsHttp3()) { + gHttpHandler->ExcludeHttp3(cinfo); + } else { + gHttpHandler->ExcludeHttp2(cinfo); + } + return IPC_OK(); +} + } // namespace net } // namespace mozilla diff --git a/netwerk/ipc/SocketProcessParent.h b/netwerk/ipc/SocketProcessParent.h index 1fa152c09df0..f98a8035c349 100644 --- a/netwerk/ipc/SocketProcessParent.h +++ b/netwerk/ipc/SocketProcessParent.h @@ -121,6 +121,9 @@ class SocketProcessParent final mozilla::ipc::IPCResult RecvODoHServiceActivated(const bool& aActivated); + mozilla::ipc::IPCResult RecvExcludeHttp2OrHttp3( + const HttpConnectionInfoCloneArgs& aArgs); + private: SocketProcessHost* mHost; UniquePtr mMemoryReportRequest; diff --git a/netwerk/protocol/http/HttpConnectionMgrParent.cpp b/netwerk/protocol/http/HttpConnectionMgrParent.cpp index 8aa436282eb4..ad10c94d31a1 100644 --- a/netwerk/protocol/http/HttpConnectionMgrParent.cpp +++ b/netwerk/protocol/http/HttpConnectionMgrParent.cpp @@ -240,11 +240,11 @@ nsresult HttpConnectionMgrParent::VerifyTraffic() { } void HttpConnectionMgrParent::ExcludeHttp2(const nsHttpConnectionInfo* ci) { - MOZ_ASSERT_UNREACHABLE("ExcludeHttp2 should not be called"); + // Do nothing. } void HttpConnectionMgrParent::ExcludeHttp3(const nsHttpConnectionInfo* ci) { - MOZ_ASSERT_UNREACHABLE("ExcludeHttp3 should not be called"); + // Do nothing. } nsresult HttpConnectionMgrParent::ClearConnectionHistory() { diff --git a/netwerk/protocol/http/nsHttpHandler.cpp b/netwerk/protocol/http/nsHttpHandler.cpp index 8ddb9e23060a..954e1ce98a0d 100644 --- a/netwerk/protocol/http/nsHttpHandler.cpp +++ b/netwerk/protocol/http/nsHttpHandler.cpp @@ -64,6 +64,7 @@ #include "mozilla/net/NeckoParent.h" #include "mozilla/net/RequestContextService.h" #include "mozilla/net/SocketProcessParent.h" +#include "mozilla/net/SocketProcessChild.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/Telemetry.h" #include "mozilla/Unused.h" @@ -2650,14 +2651,48 @@ bool nsHttpHandler::IsBeforeLastActiveTabLoadOptimization( when <= mLastActiveTabLoadOptimizationHit; } -void nsHttpHandler::ExcludeHttp2(const nsHttpConnectionInfo* ci) { - MOZ_ASSERT(OnSocketThread(), "not on socket thread"); +void nsHttpHandler::ExcludeHttp2OrHttp3Internal( + const nsHttpConnectionInfo* ci) { + LOG(("nsHttpHandler::ExcludeHttp2OrHttp3Internal ci=%s", + ci->HashKey().get())); + // The excluded list needs to be stayed synced between parent process and + // socket process, so we send this information to the parent process here. + if (XRE_IsSocketProcess()) { + MOZ_ASSERT(OnSocketThread()); - mConnMgr->ExcludeHttp2(ci); - if (!mExcludedHttp2Origins.Contains(ci->GetOrigin())) { - MutexAutoLock lock(mHttpExclusionLock); - mExcludedHttp2Origins.Insert(ci->GetOrigin()); + RefPtr cinfo = ci->Clone(); + NS_DispatchToMainThread(NS_NewRunnableFunction( + "nsHttpHandler::ExcludeHttp2OrHttp3Internal", + [cinfo{std::move(cinfo)}]() { + HttpConnectionInfoCloneArgs connInfoArgs; + nsHttpConnectionInfo::SerializeHttpConnectionInfo(cinfo, + connInfoArgs); + Unused << SocketProcessChild::GetSingleton()->SendExcludeHttp2OrHttp3( + connInfoArgs); + })); } + + MOZ_ASSERT_IF(nsIOService::UseSocketProcess() && XRE_IsParentProcess(), + NS_IsMainThread()); + MOZ_ASSERT_IF(!nsIOService::UseSocketProcess(), OnSocketThread()); + + if (ci->IsHttp3()) { + if (!mExcludedHttp3Origins.Contains(ci->GetRoutedHost())) { + MutexAutoLock lock(mHttpExclusionLock); + mExcludedHttp3Origins.Insert(ci->GetRoutedHost()); + } + mConnMgr->ExcludeHttp3(ci); + } else { + if (!mExcludedHttp2Origins.Contains(ci->GetOrigin())) { + MutexAutoLock lock(mHttpExclusionLock); + mExcludedHttp2Origins.Insert(ci->GetOrigin()); + } + mConnMgr->ExcludeHttp2(ci); + } +} + +void nsHttpHandler::ExcludeHttp2(const nsHttpConnectionInfo* ci) { + ExcludeHttp2OrHttp3Internal(ci); } bool nsHttpHandler::IsHttp2Excluded(const nsHttpConnectionInfo* ci) { @@ -2666,13 +2701,8 @@ bool nsHttpHandler::IsHttp2Excluded(const nsHttpConnectionInfo* ci) { } void nsHttpHandler::ExcludeHttp3(const nsHttpConnectionInfo* ci) { - MOZ_ASSERT(OnSocketThread(), "not on socket thread"); - - if (!mExcludedHttp3Origins.Contains(ci->GetRoutedHost())) { - MutexAutoLock lock(mHttpExclusionLock); - mExcludedHttp3Origins.Insert(ci->GetRoutedHost()); - } - mConnMgr->ExcludeHttp3(ci); + MOZ_ASSERT(ci->IsHttp3()); + ExcludeHttp2OrHttp3Internal(ci); } bool nsHttpHandler::IsHttp3Excluded(const nsACString& aRoutedHost) { diff --git a/netwerk/protocol/http/nsHttpHandler.h b/netwerk/protocol/http/nsHttpHandler.h index 7efd50c6bd97..144eff37f6fc 100644 --- a/netwerk/protocol/http/nsHttpHandler.h +++ b/netwerk/protocol/http/nsHttpHandler.h @@ -802,6 +802,7 @@ class nsHttpHandler final : public nsIHttpProtocolHandler, [[nodiscard]] nsresult SpeculativeConnectInternal( nsIURI* aURI, nsIPrincipal* aPrincipal, nsIInterfaceRequestor* aCallbacks, bool anonymous); + void ExcludeHttp2OrHttp3Internal(const nsHttpConnectionInfo* ci); // State for generating channelIds uint32_t mProcessId{0}; diff --git a/netwerk/test/unit/xpcshell.ini b/netwerk/test/unit/xpcshell.ini index c68e38c28cdc..b0a791817466 100644 --- a/netwerk/test/unit/xpcshell.ini +++ b/netwerk/test/unit/xpcshell.ini @@ -479,18 +479,18 @@ skip-if = os =='android' run-sequentially = http3server [test_http3_fatal_stream_error.js] -skip-if = tsan || os =='android' || socketprocess_networking +skip-if = tsan || os =='android' run-sequentially = node server exceptions dont replay well [test_http3_large_post.js] skip-if = tsan || os == 'win' || os =='android' [test_http3_error_before_connect.js] -skip-if = tsan || os =='android' || socketprocess_networking +skip-if = tsan || os =='android' run-sequentially = node server exceptions dont replay well [test_http3_server_not_existing.js] -skip-if = tsan || os =='android' || socketprocess_networking +skip-if = tsan || os =='android' run-sequentially = node server exceptions dont replay well [test_http3_fast_fallback.js] -skip-if = tsan || os == 'win' || os =='android' || socketprocess_networking +skip-if = tsan || os == 'win' || os =='android' run-sequentially = node server exceptions dont replay well [test_cookie_ipv6.js] [test_httpssvc_retry_with_ech.js] @@ -519,7 +519,7 @@ skip-if = socketprocess_networking # server on a local ipv6 is not started on mac run-sequentially = node server exceptions dont replay well [test_http3_version1.js] -skip-if = tsan || os == 'win' || os =='android' || socketprocess_networking +skip-if = tsan || os == 'win' || os =='android' [test_trr_domain.js] [test_http3_progress.js] skip-if = tsan || os == 'win' || os =='android' @@ -535,5 +535,5 @@ skip-if = tsan || os =='android' || (verify && (os == 'win')) || socketprocess_n run-sequentially = node server exceptions dont replay well [test_304_headers.js] [test_http3_direct_proxy.js] -skip-if = tsan || os =='android' || socketprocess_networking +skip-if = tsan || os =='android' run-sequentially = node server exceptions dont replay well