From e87fedd27c49ef5b87beaa8c07ee590fd902894f Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 20 Jul 2020 13:49:16 -0400 Subject: [PATCH] Fix shutdown crash in InitNetworkContext with multi-threaded message loop (fixes issue #2985) --- .../alloy/alloy_content_browser_client.cc | 9 ++++++++ patch/patch.cfg | 2 +- patch/patches/services_network_2718.patch | 22 +++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libcef/browser/alloy/alloy_content_browser_client.cc b/libcef/browser/alloy/alloy_content_browser_client.cc index 2a2ca9c04..912a723bf 100644 --- a/libcef/browser/alloy/alloy_content_browser_client.cc +++ b/libcef/browser/alloy/alloy_content_browser_client.cc @@ -1296,6 +1296,15 @@ void AlloyContentBrowserClient::ConfigureNetworkContextParams( const base::FilePath& relative_partition_path, network::mojom::NetworkContextParams* network_context_params, network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) { + // This method may be called during shutdown when using multi-threaded + // message loop mode. In that case exit early to avoid crashes. + if (!SystemNetworkContextManager::GetInstance()) { + // This must match the value expected in + // StoragePartitionImpl::InitNetworkContext. + network_context_params->context_name = "magic_shutting_down"; + return; + } + Profile* profile = Profile::FromBrowserContext(context); profile->ConfigureNetworkContextParams(in_memory, relative_partition_path, network_context_params, diff --git a/patch/patch.cfg b/patch/patch.cfg index d602e0317..1a021dade 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -401,7 +401,7 @@ patches = [ # https://bitbucket.org/chromiumembedded/cef/issues/2718 # # Fix shutdown crash in InitNetworkContext with multi-threaded message loop. - # https://bitbucket.org/chromiumembedded/cef/issues/2703 + # https://bitbucket.org/chromiumembedded/cef/issues/2985 # # Compute correct default quota when cache_path is unspecified. 'name': 'services_network_2718', diff --git a/patch/patches/services_network_2718.patch b/patch/patches/services_network_2718.patch index adf820061..04be3f579 100644 --- a/patch/patches/services_network_2718.patch +++ b/patch/patches/services_network_2718.patch @@ -1,5 +1,5 @@ diff --git content/browser/storage_partition_impl.cc content/browser/storage_partition_impl.cc -index a0034ad3a21d..80fa8da263ac 100644 +index a0034ad3a21d..bf694fdf18d0 100644 --- content/browser/storage_partition_impl.cc +++ content/browser/storage_partition_impl.cc @@ -490,10 +490,6 @@ class LoginHandlerDelegate { @@ -40,15 +40,15 @@ index a0034ad3a21d..80fa8da263ac 100644 storage::GetDefaultDeviceInfoHelper(), std::move(callback)); } -@@ -2396,7 +2390,10 @@ void StoragePartitionImpl::InitNetworkContext() { - network_context_.reset(); - GetNetworkService()->CreateNetworkContext( - network_context_.BindNewPipeAndPassReceiver(), std::move(context_params)); -- DCHECK(network_context_); -+ if (!network_context_) { -+ // May happen during shutdown. +@@ -2371,6 +2365,11 @@ void StoragePartitionImpl::InitNetworkContext() { + GetContentClient()->browser()->ConfigureNetworkContextParams( + browser_context_, is_in_memory_, relative_partition_path_, + context_params.get(), cert_verifier_creation_params.get()); ++ if (context_params->context_name && ++ *context_params->context_name == "magic_shutting_down") { ++ // Don't re-initialize the network context during shutdown. + return; + } - - network_context_client_receiver_.reset(); - network_context_->SetClient( + devtools_instrumentation::ApplyNetworkContextParamsOverrides( + browser_context_, context_params.get()); + DCHECK(!context_params->cert_verifier_params)