From dfcfb51befb6079817ce3582a2c111668bb8da05 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 26 Nov 2019 16:26:48 -0500 Subject: [PATCH] Fix shutdown crash in InitNetworkContext with multi-threaded message loop (fixes issue #2703) --- libcef/browser/content_browser_client.cc | 5 +++++ patch/patch.cfg | 3 +++ .../patches/services_network_request_id_2718.patch | 14 +++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libcef/browser/content_browser_client.cc b/libcef/browser/content_browser_client.cc index 2e36af867..6555e7f86 100644 --- a/libcef/browser/content_browser_client.cc +++ b/libcef/browser/content_browser_client.cc @@ -1288,6 +1288,11 @@ CefContentBrowserClient::CreateNetworkContext( content::BrowserContext* context, bool in_memory, const base::FilePath& relative_partition_path) { + // 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()) + return mojo::Remote(); + Profile* profile = Profile::FromBrowserContext(context); return profile->CreateNetworkContext(in_memory, relative_partition_path); } diff --git a/patch/patch.cfg b/patch/patch.cfg index 5e1628498..c12b263cb 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -397,6 +397,9 @@ patches = [ # - Remove the non-nullptr WebContents requirement from # NetworkServiceClient::OnAuthRequired. # https://bitbucket.org/chromiumembedded/cef/issues/2718 + # + # Fix shutdown crash in InitNetworkContext with multi-threaded message loop. + # https://bitbucket.org/chromiumembedded/cef/issues/2703 'name': 'services_network_request_id_2718', }, { diff --git a/patch/patches/services_network_request_id_2718.patch b/patch/patches/services_network_request_id_2718.patch index be4d3a7b2..25fb3d98e 100644 --- a/patch/patches/services_network_request_id_2718.patch +++ b/patch/patches/services_network_request_id_2718.patch @@ -1,5 +1,5 @@ diff --git content/browser/storage_partition_impl.cc content/browser/storage_partition_impl.cc -index 818a6370957a..64ab8e2462b5 100644 +index 818a6370957a..46282b320b0b 100644 --- content/browser/storage_partition_impl.cc +++ content/browser/storage_partition_impl.cc @@ -577,10 +577,6 @@ class LoginHandlerDelegate { @@ -26,6 +26,18 @@ index 818a6370957a..64ab8e2462b5 100644 new LoginHandlerDelegate(std::move(auth_challenge_responder), std::move(web_contents_getter), auth_info, is_request_for_main_frame, process_id, routing_id, +@@ -2277,7 +2267,10 @@ void StoragePartitionImpl::GetQuotaSettings( + void StoragePartitionImpl::InitNetworkContext() { + network_context_ = GetContentClient()->browser()->CreateNetworkContext( + browser_context_, is_in_memory_, relative_partition_path_); +- DCHECK(network_context_); ++ if (!network_context_) { ++ // May happen during shutdown. ++ return; ++ } + + network_context_client_receiver_.reset(); + network_context_->SetClient( diff --git services/network/public/cpp/simple_url_loader.cc services/network/public/cpp/simple_url_loader.cc index 1cc4198e6057..0fae6dbe25a2 100644 --- services/network/public/cpp/simple_url_loader.cc