Fix shutdown crash in InitNetworkContext with multi-threaded message loop (fixes issue #2985)

This commit is contained in:
Marshall Greenblatt 2020-07-20 13:49:16 -04:00
parent fab2af8876
commit e87fedd27c
3 changed files with 21 additions and 12 deletions

View File

@ -1296,6 +1296,15 @@ void AlloyContentBrowserClient::ConfigureNetworkContextParams(
const base::FilePath& relative_partition_path, const base::FilePath& relative_partition_path,
network::mojom::NetworkContextParams* network_context_params, network::mojom::NetworkContextParams* network_context_params,
network::mojom::CertVerifierCreationParams* cert_verifier_creation_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* profile = Profile::FromBrowserContext(context);
profile->ConfigureNetworkContextParams(in_memory, relative_partition_path, profile->ConfigureNetworkContextParams(in_memory, relative_partition_path,
network_context_params, network_context_params,

View File

@ -401,7 +401,7 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2718 # https://bitbucket.org/chromiumembedded/cef/issues/2718
# #
# Fix shutdown crash in InitNetworkContext with multi-threaded message loop. # 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. # Compute correct default quota when cache_path is unspecified.
'name': 'services_network_2718', 'name': 'services_network_2718',

View File

@ -1,5 +1,5 @@
diff --git content/browser/storage_partition_impl.cc content/browser/storage_partition_impl.cc 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
+++ content/browser/storage_partition_impl.cc +++ content/browser/storage_partition_impl.cc
@@ -490,10 +490,6 @@ class LoginHandlerDelegate { @@ -490,10 +490,6 @@ class LoginHandlerDelegate {
@ -40,15 +40,15 @@ index a0034ad3a21d..80fa8da263ac 100644
storage::GetDefaultDeviceInfoHelper(), std::move(callback)); storage::GetDefaultDeviceInfoHelper(), std::move(callback));
} }
@@ -2396,7 +2390,10 @@ void StoragePartitionImpl::InitNetworkContext() { @@ -2371,6 +2365,11 @@ void StoragePartitionImpl::InitNetworkContext() {
network_context_.reset(); GetContentClient()->browser()->ConfigureNetworkContextParams(
GetNetworkService()->CreateNetworkContext( browser_context_, is_in_memory_, relative_partition_path_,
network_context_.BindNewPipeAndPassReceiver(), std::move(context_params)); context_params.get(), cert_verifier_creation_params.get());
- DCHECK(network_context_); + if (context_params->context_name &&
+ if (!network_context_) { + *context_params->context_name == "magic_shutting_down") {
+ // May happen during shutdown. + // Don't re-initialize the network context during shutdown.
+ return; + return;
+ } + }
devtools_instrumentation::ApplyNetworkContextParamsOverrides(
network_context_client_receiver_.reset(); browser_context_, context_params.get());
network_context_->SetClient( DCHECK(!context_params->cert_verifier_params)