From 149ccf946fc346d90cc9e4f2db3e82d5133fe430 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 20 Jul 2020 14:03:15 -0400 Subject: [PATCH] Fix shutdown crash in InitNetworkContext with multi-threaded message loop (fixes issue #2985) --- libcef/browser/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/content_browser_client.cc b/libcef/browser/content_browser_client.cc index 2147df475..15f8176e7 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -1318,6 +1318,15 @@ void CefContentBrowserClient::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 e55debd1a..97eb538d7 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -396,7 +396,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 d19c44585..9c6cf33df 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 f06c5b512342..1e8d5eef47fc 100644 +index f06c5b512342..ba2c1eae9324 100644 --- content/browser/storage_partition_impl.cc +++ content/browser/storage_partition_impl.cc @@ -489,10 +489,6 @@ class LoginHandlerDelegate { @@ -40,15 +40,15 @@ index f06c5b512342..1e8d5eef47fc 100644 storage::GetDefaultDeviceInfoHelper(), std::move(callback)); } -@@ -2387,7 +2381,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. +@@ -2376,6 +2370,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( + DCHECK(!context_params->cert_verifier_creation_params) + << "|cert_verifier_creation_params| should not be set in the " + "NetworkContextParams, as they will eventually be removed when the "