Fix shutdown crash in RenderProcessHostImpl::Cleanup (fixes issue #3276)

Execute all pending UI thread tasks at the beginning of the shutdown sequence.
This commit is contained in:
Marshall Greenblatt 2022-03-09 13:13:45 -05:00
parent 113a96be0d
commit a513e01b01
1 changed files with 10 additions and 0 deletions

View File

@ -482,6 +482,16 @@ void CefMainRunner::FinishShutdownOnUIThread(
base::WaitableEvent* uithread_shutdown_event) {
CEF_REQUIRE_UIT();
// Execute all pending tasks now before proceeding with shutdown. Otherwise,
// objects bound to tasks and released at the end of shutdown via
// BrowserTaskExecutor::Shutdown may attempt to access other objects that have
// already been destroyed (for example, if teardown results in a call to
// RenderProcessHostImpl::Cleanup).
content::BrowserTaskExecutor::RunAllPendingTasksOnThreadForTesting(
content::BrowserThread::UI);
content::BrowserTaskExecutor::RunAllPendingTasksOnThreadForTesting(
content::BrowserThread::IO);
static_cast<content::ContentMainRunnerImpl*>(main_runner_.get())
->ShutdownOnUIThread();