Hang in RunMessageLoop | win32 C++

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.

Hang in RunMessageLoop | win32 C++

Postby harsh » Wed Feb 28, 2024 4:14 am

We are using win32 C++ CEF version 108.4.13 with chromium version 108.0.5359.125 in our windows desktop application. As per Microsoft Partner Dashboard reports, hangs are reported in CEF with following stacktrace.

cef hang.png
cef hang.png (327.49 KiB) Viewed 573 times


Here are some points related to our usage:
1. We are not able to reproduce it on our internal machines.
2. We are using CEF in sandboxed mode and we create only a single browser window with “hidden menu” and “close button disabled”.
3. How the message loop will close then? There is a windows timer routine of 15 minutes after which we close the browser window and invoke CefShutDown(). Also the webpage which we render to users, is a customized webpage which has a button, if user clicks that button, then also browser window is closed and CefShutDown() is invoked. So in any case CefShutDown() will get call in maximum 15 minutes.
4. This legacy code is working fine most of the time but we are noticing this hang 15% of the total times our application is invoked.
multi_threaded_message_loop is set to false.
5. Can force closing CEF browser cause this hang? Because depending on some conditions sometimes we do force close and sometimes don’t.
6. We are also calling CefExecuteProcess() even though we have requirement of creating just a single browser window. We are planning to remove call to CefExecuteProcess() in next release.
7. Here is how we are using CEF in our application, any pointers/lead will be highly appreciated.

Code: Select all
void InitiateCEFNotificationWorkflow(HINSTANCE hInstance, CefRefPtr<CefCommandLine> command_line) {
    const std::string& process_type = command_line->GetSwitchValue("type");
 
    CefMainArgs main_args(hInstance);
    CefRefPtr<CEFAppHandler> app(new CEFAppHandler);
 
    void* sandbox_info = nullptr;
#ifndef _DEBUG
    CefScopedSandboxInfo scoped_sandbox;
    sandbox_info = scoped_sandbox.sandbox_info();
#endif
    CefExecuteProcess(main_args, app.get(), sandbox_info);
}
 
 
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {
    CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
    command_line->InitFromString(::GetCommandLineW());
    if (command_line->HasSwitch("type")) {
        InitiateCEFNotificationWorkflow(hInstance, command_line);
        return;
    }
   
    CefMainArgs main_args(hInstance);
    // We have created CEFAppHandler inherited from classes CefApp, CefBrowserProcessHandler, CefRenderProcessHandler
    CefRefPtr<CEFAppHandler> app(new CEFAppHandler);
    void* sandbox_info = NULL;
#ifndef _DEBUG
    CefScopedSandboxInfo scoped_sandbox;
    sandbox_info = scoped_sandbox.sandbox_info();
#endif
    // CefExecuteProcess returns -1 for the host process
    int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
    if(exit_code >= 0) {   
        return 0;
    }
    CefSettings settings;
    settings.multi_threaded_message_loop = false;
    CefInitialize(main_args, settings, app.get(), sandbox_info);
   
    // Creating the browser window here and make it invisible
    CefRunMessageLoop();
    // Make the browser window visible in callback OnLoadEnd()
 
    //Set the error mode to disable any UI if a crash happens
    //This check has been added to address the following bug reported
    //in CEF https://bitbucket.org/chromiumembedded/cef/issues/1037/cef3-io-thread-crash-on-a-urlrequest-leak
    SetErrorMode(SEM_NOGPFAULTERRORBOX);
    CefShutdown();
    return 0;
}
harsh
Techie
 
Posts: 30
Joined: Mon Dec 09, 2019 11:17 am

Re: Hang in RunMessageLoop | win32 C++

Postby magreenblatt » Wed Feb 28, 2024 11:45 am

Where/when are you calling CefQuitMessageLoop?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Hang in RunMessageLoop | win32 C++

Postby harsh » Wed Feb 28, 2024 12:24 pm

We have created a C++ class CEFClientHandler inherited from CefClient, CefLifeSpanHandler, CefLoadHandler, CefRenderHandler, CefRequestHandler, CefContextMenuHandler and CefDisplayHandler. We have overridden OnBeforeClose() method in CEFClientHandler class. In OnBeforeClose() method, we are decrementing the browser window count and if count of browser windows becomes 0, we are doing cleanup and calling CefQuitMessageLoop().
harsh
Techie
 
Posts: 30
Joined: Mon Dec 09, 2019 11:17 am

Re: Hang in RunMessageLoop | win32 C++

Postby magreenblatt » Wed Feb 28, 2024 12:33 pm

Can force closing CEF browser cause this hang?

How are you "force closing" the browser?

Microsoft Partner Dashboard reports, hangs are reported in CEF with following stacktrace.

This stack trace looks normal (e.g. the message loop is still running). What else does Microsoft Partner Dashboard show you related to this issue?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Hang in RunMessageLoop | win32 C++

Postby harsh » Wed Feb 28, 2024 12:47 pm

We have a CEFClientHandler object g_handler. We are force closing it after timer of 15 minutes gets over, g_handler->GetBrowser()->GetHost()->CloseBrowser(true);

Though the stack trace is normal but it is in hang state as Microsoft Partner Dashboard says "APPLICATION_HANG_ENDTASK_HungThreadIsIdle_cfffffff_libcef.dll!Unknown"
That means message loop is not responding anymore.
harsh
Techie
 
Posts: 30
Joined: Mon Dec 09, 2019 11:17 am

Re: Hang in RunMessageLoop | win32 C++

Postby harsh » Thu Feb 29, 2024 11:25 pm

@magreenblatt Please let us know if you need any further details, any pointers/lead will help us narrow down this issue.
harsh
Techie
 
Posts: 30
Joined: Mon Dec 09, 2019 11:17 am

Re: Hang in RunMessageLoop | win32 C++

Postby magreenblatt » Fri Mar 01, 2024 12:00 am

Can you post call stacks for the other threads?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Hang in RunMessageLoop | win32 C++

Postby harsh » Fri Mar 01, 2024 4:52 am

Here is the complete stack trace for all the threads
AllStackTraces.txt
(30.3 KiB) Downloaded 19 times
harsh
Techie
 
Posts: 30
Joined: Mon Dec 09, 2019 11:17 am

Re: Hang in RunMessageLoop | win32 C++

Postby magreenblatt » Fri Mar 01, 2024 11:28 am

The stack traces show that all message loops are idle. I suspect that your application is not actually calling CefQuitMessageLoop.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Hang in RunMessageLoop | win32 C++

Postby harsh » Fri Mar 15, 2024 4:34 am

Today we are calling CefQuitMessageLoop() only in CefClientHandler::OnBeforeClose(). As we are doing force close of browser window in most of the scenarios(browser->GetHost()->CloseBrowser(true)), is there a chance that CefClientHandler::OnBeforeClose() does not get trigger?

Do you think calling
Code: Select all
CefPostDelayedTask(TID_UI, CefCreateClosureTask(base::BindOnce(CefQuitMessageLoop)), <SOME_CUSTOM_TIME>);
will be helpful in case there is a bug in our workflow which is not able to call CEFQuitMessageLoop()?
harsh
Techie
 
Posts: 30
Joined: Mon Dec 09, 2019 11:17 am

Next

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 186 guests