From 01d0f7dcc5a596e1f8ff1432bc4a7a4f72389159 Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Thu, 9 Jun 2022 11:59:38 +0000 Subject: [PATCH] Bug 1770485 - Make content process socket threads use a regular event loop, with a pref r=necko-reviewers,kershaw The custom event loop is only needed in the parent process or socket process, where it is used to interleave runnable processing with socket response processing. But in content processes, we don't get any data from any socket directly. Pref added, and pref disabled for many necko xpcshell tests Differential Revision: https://phabricator.services.mozilla.com/D147094 --- dom/base/test/unit_ipc/xpcshell.ini | 4 ++- modules/libpref/init/StaticPrefList.yaml | 5 +++ netwerk/base/nsSocketTransportService2.cpp | 24 ++++++++++++-- netwerk/test/unit_ipc/xpcshell.ini | 37 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/dom/base/test/unit_ipc/xpcshell.ini b/dom/base/test/unit_ipc/xpcshell.ini index 50a9502f9410..e02cfb4e45a4 100644 --- a/dom/base/test/unit_ipc/xpcshell.ini +++ b/dom/base/test/unit_ipc/xpcshell.ini @@ -1,9 +1,11 @@ [DEFAULT] head = -skip-if = toolkit == 'android' +skip-if = toolkit == 'android' || socketprocess_networking support-files = !/dom/base/test/unit/test_bug553888.js !/dom/base/test/unit/test_xhr_document.js [test_bug553888_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_xhr_document_ipc.js] +prefs = network.allow_raw_sockets_in_content_processes=true diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 1a623f603e17..4d5554f7451a 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -11182,6 +11182,11 @@ value: 1 mirror: always +- name: network.allow_raw_sockets_in_content_processes + type: bool + value: false + mirror: once + #--------------------------------------------------------------------------- # Prefs starting with "nglayout." #--------------------------------------------------------------------------- diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 5375a2d7c13e..10bd930f330e 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -17,6 +17,7 @@ #include "mozilla/PublicSSL.h" #include "mozilla/ReverseIterator.h" #include "mozilla/Services.h" +#include "mozilla/StaticPrefs_network.h" #include "mozilla/Telemetry.h" #include "nsASocketHandler.h" #include "nsError.h" @@ -768,9 +769,26 @@ nsSocketTransportService::Init() { } nsCOMPtr thread; - nsresult rv = - NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), this); - NS_ENSURE_SUCCESS(rv, rv); + + if (!XRE_IsContentProcess() || + StaticPrefs::network_allow_raw_sockets_in_content_processes_AtStartup()) { + nsresult rv = + NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), this); + NS_ENSURE_SUCCESS(rv, rv); + } else { + // In the child process, we just want a regular nsThread with no socket + // polling. So we don't want to run the nsSocketTransportService runnable on + // it. + nsresult rv = + NS_NewNamedThread("Socket Thread", getter_AddRefs(thread), nullptr); + NS_ENSURE_SUCCESS(rv, rv); + + // Set up some of the state that nsSocketTransportService::Run would set. + PRThread* prthread = nullptr; + thread->GetPRThread(&prthread); + gSocketThread = prthread; + mRawThread = thread; + } { MutexAutoLock lock(mLock); diff --git a/netwerk/test/unit_ipc/xpcshell.ini b/netwerk/test/unit_ipc/xpcshell.ini index 8a300dee6768..6ed4bc009105 100644 --- a/netwerk/test/unit_ipc/xpcshell.ini +++ b/netwerk/test/unit_ipc/xpcshell.ini @@ -1,5 +1,6 @@ [DEFAULT] head = head_channels_clone.js head_trr_clone.js head_http3_clone.js +skip-if = socketprocess_networking support-files = child_channel_id.js !/netwerk/test/unit/test_XHR_redirects.js @@ -70,35 +71,57 @@ support-files = [test_cookie_header_stripped.js] [test_cacheflags_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_cache-entry-id_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_cache_jar_wrap.js] [test_channel_close_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_cookiejars_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_dns_cancel_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_dns_service_wrap.js] [test_duplicate_headers_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_event_sink_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_gio_protocol_wrap.js] skip-if = (toolkit != 'gtk') [test_head_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_headers_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_httpsuspend_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_post_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_predictor_wrap.js] [test_progress_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect-caching_canceled_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect-caching_failure_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect-caching_passing_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect_canceled_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect_failure_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true # Do not test the channel.redirectTo() API under e10s until 827269 is resolved [test_redirect_from_script_wrap.js] skip-if = true [test_redirect_passing_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect_different-protocol_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_reentrancy_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_resumable_channel_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_simple_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_http3_prio_disabled_wrap.js] skip-if = os == 'android' run-sequentially = http3server @@ -106,21 +129,35 @@ run-sequentially = http3server skip-if = os == 'android' run-sequentially = http3server [test_xmlhttprequest_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_XHR_redirects.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_redirect_history_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_reply_without_content_type_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_getHost_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_alt-data_simple_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_alt-data_stream_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_alt-data_closeWithStatus_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_original_sent_received_head_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_channel_id.js] [test_trackingProtection_annotateChannels_wrap1.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_trackingProtection_annotateChannels_wrap2.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_channel_priority_wrap.js] [test_multipart_streamconv_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_alt-data_cross_process_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_httpcancel_wrap.js] +prefs = network.allow_raw_sockets_in_content_processes=true [test_dns_by_type_resolve_wrap.js] [test_trr_httpssvc_wrap.js] skip-if = os == "android"