From f048a5ddba5392864bad40e5ea80ef381418f594 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 9 Apr 2021 14:22:48 -0400 Subject: [PATCH] Fix server thread assertion on CEF shutdown (see issue #2969) The server thread was not guaranteed to be released in the correct scope on CEF shutdown. This resulted in occasional thread_restrictions assertions on ceftests shutdown after running the URLRequestTest suite with the Chrome runtime enabled. --- libcef/browser/server_impl.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libcef/browser/server_impl.cc b/libcef/browser/server_impl.cc index 38c226c6d..8e36585ab 100644 --- a/libcef/browser/server_impl.cc +++ b/libcef/browser/server_impl.cc @@ -595,7 +595,7 @@ void CefServerImpl::ShutdownOnUIThread() { if (thread_) { // Stop the handler thread as a background task so the UI thread isn't // blocked. - CEF_POST_BACKGROUND_TASK(BindOnce( + auto task = base::BindOnce( [](std::unique_ptr thread) { // Calling PlatformThread::Join() on the UI thread is otherwise // disallowed. @@ -603,7 +603,15 @@ void CefServerImpl::ShutdownOnUIThread() { scoped_allow_sync_primitives; thread.reset(); }, - std::move(thread_))); + std::move(thread_)); + + // Make sure the task is executed on shutdown. Otherwise, |thread| might + // be released outside of the correct scope. + base::PostTask( + FROM_HERE, + {base::ThreadPool(), base::TaskPriority::BEST_EFFORT, + base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()}, + std::move(task)); // Release the reference that was added in StartupOnUIThread(). Release();