CEF crashing in Shutdown

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CEF crashing in Shutdown

Postby aataneja » Wed Jul 28, 2021 1:47 pm

We have upgraded CEF to 90.0.4430.212 version to support apple silicon (Arm64) architecture. We are successfully able to load the URL in the window but while closing the window and exiting, the CEF is crashing at the time of shutdown.
We are using browser->GetHost->CloseBrowser(false) to close the browser.
Also tried closing by passing true (force close) and also tried using TryCloseBrowser in a loop, but it seems tryclosebrowser keeps on returning false and it results in infinite loop.
Below is the stack trace :

Thread 0 Crashed:: CrBrowserMain Dispatch queue: com.apple.main-thread
0 org.chromium.ContentShell.framework 0x0000000108606008 cef_time_delta + 2256220
1 org.chromium.ContentShell.framework 0x0000000108605fd4 cef_time_delta + 2256168
2 org.chromium.ContentShell.framework 0x00000001083c1eac cef_log + 84
3 <appname> 0x000000010329a338 cef_log + 60 (libcef_dll_dylib.cc:1731)
4 <appname> 0x000000010318da28 cef::logging::LogMessage::~LogMessage() + 112 (cef_logging.cc:186)
5 <appname> 0x000000010318da98 cef::logging::LogMessage::~LogMessage() + 32 (cef_logging.cc:184)
6 <appname> 0x0000000103274518 shutdown_checker::AssertNotShutdown() + 176 (shutdown_checker.cc:52)
7 <appname> 0x00000001031b8090 (anonymous namespace)::life_span_handler_on_before_close(_cef_life_span_handler_t*, _cef_browser_t*) + 28 (life_span_handler_cpptoc.cc:194)
8 org.chromium.ContentShell.framework 0x00000001056e7f44 cef_label_button_create + 15956
9 org.chromium.ContentShell.framework 0x000000010832ea1c ChromeAppModeStart_v6 + 7292524
10 org.chromium.ContentShell.framework 0x00000001083178a8 ChromeAppModeStart_v6 + 7197944
11 org.chromium.ContentShell.framework 0x0000000108334ccc ChromeAppModeStart_v6 + 7317788
12 org.chromium.ContentShell.framework 0x000000010833c8dc ChromeAppModeStart_v6 + 7349548
13 org.chromium.ContentShell.framework 0x0000000108361c64 ChromeAppModeStart_v6 + 7502004
14 org.chromium.ContentShell.framework 0x000000010833c1dc ChromeAppModeStart_v6 + 7347756
15 <appname> 0x0000000103298ab4 cef_shutdown + 24 (libcef_dll_dylib.cc:987)
16 <appname> 0x000000010329b568 CefShutdown() + 16 (libcef_dll_wrapper.cc:120)
17 <appname> 0x0000000103035110 client::MainContextImpl::Shutdown() + 552 (main_context_impl.cc:267)

Any help/leads will be appreciated.
aataneja
Newbie
 
Posts: 9
Joined: Fri Jul 26, 2019 2:46 am

Re: CEF crashing in Shutdown

Postby magreenblatt » Wed Jul 28, 2021 3:36 pm

What MacOS and Xcode version? Does the crash occur with the CEF sample applications?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF crashing in Shutdown

Postby aataneja » Thu Jul 29, 2021 4:44 am

OS Version : 11.0.1
Xcode Version : 12.5.1
And cefsimple is working fine.
The difference is that in our app, we are expliciting calling browser->GetHost()->CloseBrowser(true) from the function onBeforeBrowse in client_handler.cc . This is done to handle a business case depending on some URL query parameters whereas I could not find closeBroser call in the cef simple app.

After debugging and seeing the crash trace it seems, we are invoking CEF shutdown which sets the flag to true (setIsShutdown() in shutdown_checker.cc) and after just a moment, cef receives a callback on life_span_handler_on_before_close which asserts AssertNotShutdown() and since the flag is set to true, so the DCHECK fails and hence crash is observerd.

So, one more question, which should be executed :
1. CefShutdown (in libcef_dll_wrapper.cc)
2. life_span_handler_on_before_close (life_span_handler_cpptoc.cc)

In our case, CefShutdown is called first and then life_span_handler_on_before_close. Is this the potential reason for crash?
If yes, how to wait to close all references?
aataneja
Newbie
 
Posts: 9
Joined: Fri Jul 26, 2019 2:46 am

Re: CEF crashing in Shutdown

Postby magreenblatt » Thu Jul 29, 2021 9:59 am

You need to wait for OnBeforeClose to be called for all browsers, and then exit the message loop by calling CefQuitMessageLoop or similar, before calling CefShutdown.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF crashing in Shutdown

Postby aataneja » Thu Jul 29, 2021 12:11 pm

The error in CEF log is "FATAL:shutdown_checker.cc(52)] Check failed: !IsCefShutdown(). Object reference incorrectly held at CefShutdown "
Yes, how do I wait for all browsers to close. I tried the following approaches for this :
int waitTime = 0;
while (waitTime < 10) {
bool closed = browser_->GetHost()->TryCloseBrowser();
if (closed) break;
sleep(1);
waitTime++;
}
browser->GetHost()->CloseBrowser(false);

and
while (1) {
bool closed = browser_->GetHost()->TryCloseBrowser();
if (closed) break;
sleep(1);
}
browser->GetHost()->CloseBrowser(false);
But it went for infinite loop.
Also , following is the definition inside my onbeforeclose function in client_handler.cc

void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();

if (--browser_count_ == 0) {
// Remove and delete message router handlers.
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
for (; it != message_handler_set_.end(); ++it) {
message_router_->RemoveHandler(*(it));
delete *(it);
}
message_handler_set_.clear();
message_router_ = nullptr;
CefQuitMessageLoop();
}
NotifyBrowserClosed(browser);
}

And doclose function is as follows :
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
NotifyBrowserClosing(browser);

CloseWindow(); // this function closes a window ( RootWindowDelegate)

OnBeforeClose(browser);

return false;
}
aataneja
Newbie
 
Posts: 9
Joined: Fri Jul 26, 2019 2:46 am

Re: CEF crashing in Shutdown

Postby magreenblatt » Thu Jul 29, 2021 12:45 pm

Indeed, your code is wrong. Look at the CEF sample applications for correct usage.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF crashing in Shutdown

Postby aataneja » Thu Jul 29, 2021 12:59 pm

This is what is there inside sample app:
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();

NotifyBrowserClosing(browser);

// Allow the close. For windowed browsers this will result in the OS close
// event being sent.
return false;
}

void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();

if (--browser_count_ == 0) {
// Remove and delete message router handlers.
MessageHandlerSet::const_iterator it = message_handler_set_.begin();
for (; it != message_handler_set_.end(); ++it) {
message_router_->RemoveHandler(*(it));
delete *(it);
}
message_handler_set_.clear();
message_router_ = nullptr;
}

NotifyBrowserClosed(browser);
}

Can you please suggest exactly what should be changed as 80% of the code is same, and where do i call CEFquitmessageloop if not here.
aataneja
Newbie
 
Posts: 9
Joined: Fri Jul 26, 2019 2:46 am

Re: CEF crashing in Shutdown

Postby aataneja » Fri Jul 30, 2021 7:29 am

If I follow as per mentioned in CEF simple app, my onBeforeClose() function is not called after DoClose().
Can you please suggest why onbeforeclose is not being called and the app remains stuck due to CEFQuitMessageLoop is not done.
aataneja
Newbie
 
Posts: 9
Joined: Fri Jul 26, 2019 2:46 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 21 guests