c++linuxmultithreadingchromium-embedded

Creating new thread before 'CefExecuteProcess' causes CEF application to crash with SIGTRAP


I start my CEF application with the below code

void EmtpyThreadFunc()
{
    // create one infinite loop thread to keep the process alive
    while (true)
    {
        sleep(1000);
    }
}


int main(int argc, char* argv[])
{
    std::string name = "MyTestProject";
    //std::thread sampleThread(EmtpyThreadFunc); // Enabling this causes the program to crash

     // Parse command-line arguments.
    auto commandLine = CefCommandLine::CreateCommandLine();
    commandLine->InitFromArgv(argc, argv);

    // Create a ClientApp of the correct type.
    CefRefPtr<CefApp> app;

    /* code to initialize app is removed */
    

    CefMainArgs args(argc, argv);

    // Execute the secondary process, if any.
    int exitCode = CefExecuteProcess(args, app, NULL);
    if (exitCode >= 0)
    {
        return exitCode;
    }

    // rest of codes

}

Enabling sampleThread which does nothing but run an infinite while loop causes my CEF application to exit with SIGTRAP.

The stack is given below

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
#0  0x00007f207dc82b02 in operator() () at ../../services/service_manager/zygote/zygote_main_linux.cc:161
161     ../../services/service_manager/zygote/zygote_main_linux.cc: No such file or directory.
[Current thread is 1 (Thread 0x7f2075d31d80 (LWP 86988))]
(gdb) bt
#0  0x00007f207dc82b02 in operator() () at ../../services/service_manager/zygote/zygote_main_linux.cc:161
#1  EnterLayerOneSandbox () at ../../services/service_manager/zygote/zygote_main_linux.cc:161
#2  ZygoteMain () at ../../services/service_manager/zygote/zygote_main_linux.cc:222
#3  0x00007f207c06748c in RunZygote () at ../../content/app/content_main_runner_impl.cc:471
#4  0x00007f207c068791 in Run () at ../../content/app/content_main_runner_impl.cc:876
#5  0x00007f207dc8383a in MainRun () at ../../services/service_manager/embedder/main.cc:430
#6  0x00007f207dc83d0e in Main () at ../../services/service_manager/embedder/main.cc:477
#7  0x00007f207c066cf1 in content::ContentMain(content::ContentMainParams const&) () at ../../content/app/content_main.cc:19
#8  0x00007f207c29b7a0 in CefExecuteProcess () at ../../cef/libcef/browser/context.cc:220
#9  0x00007f2079f6b6da in cef_execute_process () at ../../cef/libcef_dll/libcef_dll.cc:78
#10 0x00005602a0a53984 in CefExecuteProcess(CefMainArgs const&, scoped_refptr<CefApp>, void*) ()

I'm using CEF 81.2.16 in Linux, saw almost the same issue with CEF 121 also. the following command line args are used.

--no-sandbox  --x=0 --y=0 --width=1281 --height=801 --disable-pinch --disable-web-security --log-severity=disable --ignore-certificate-errors --showDevTools

Solution

  • The sandbox initialization requires that other threads are not spawned in pre-sandbox code. --no-sandbox doesn't disable this requirement. You may not create threads before the call to CefExecuteProcess().

    See services/service_manager/zygote/zygote_main_linux.cc:161