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;
}