[solved] Crash when calling CefShutdown on Linux

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.

[solved] Crash when calling CefShutdown on Linux

Postby olzzen » Wed Sep 15, 2021 4:25 am

CEF is crashing when calling CefShutdown from within our client-application on linux. We have ensured that the initialization/deinitialization takes place in the same thread. We are using a foreign Eventloop (QEventLoop, QApplication) and trigger the call to CefDoMessageLoopWork every 50ms.

Basically the code looks like:
CefInitialize(...)
CreateBrowser(...)
EventLoop.exec()
CefShutdown()

When the close button (X) is clicked, ClientHandler::OnBeforeClose is called which triggers a signal to exit the EventLoop.

Following the application output:

[0915/105446.791234:ERROR:gl_surface_egl.cc(780)] EGL Driver message (Critical) eglMakeCurrent: Failed to make the GLX context current
[0915/105446.791474:ERROR:skia_output_surface_impl_on_gpu.cc(1521)] Failed to make current.
[0915/105446.791684:ERROR:skia_output_surface_impl_on_gpu.cc(1521)] Failed to make current.
[0915/105446.797629:WARNING:connection.cc(61)] X error received. Request: DestroyWindowRequest, Error: WindowError{.sequence = 348, .bad_value = 37748738, .minor_opcode = 0, .major_opcode = 4}
[0915/105446.799032:FATAL:alloy_browser_main.cc(246)] Check failed: global_request_context_->HasOneRef().

Thread 1 "CEFViewer" received signal SIGTRAP, Trace/breakpoint trap.
0x00007fffef159e37 in operator() () at ../../base/logging.cc:889
889 ../../base/logging.cc: Datei oder Verzeichnis nicht gefunden.
Missing separate debuginfos, use: zypper install kdebase4-workspace-libs-debuginfo-4.11.22-2.8.x86_64 libX11-xcb1-debuginfo-1.6.2-12.15.1.x86_64

(gdb) bt
#0 0x00007fffef159e37 in operator() () at ../../base/logging.cc:889
#1 0x00007fffef159e37 in ~LogMessage() () at ../../base/logging.cc:889
#2 0x00007fffef15a0ee in logging::LogMessage::~LogMessage() () at ../../base/logging.cc:583
#3 0x00007fffeefc9358 in PostMainMessageLoopRun() () at ../../cef/libcef/browser/alloy/alloy_browser_main.cc:246
#4 0x00007fffec58aa77 in ShutdownThreadsAndCleanUp() () at ../../content/browser/browser_main_loop.cc:1036
#5 0x00007fffec58c519 in Shutdown() () at ../../content/browser/browser_main_runner_impl.cc:179
#6 0x00007fffef021c2c in FinalizeShutdown() () at ../../cef/libcef/browser/main_runner.cc:496
#7 0x00007fffef021af2 in Shutdown() () at ../../cef/libcef/browser/main_runner.cc:274
#8 0x00007fffeeff2f8a in Shutdown() () at ../../cef/libcef/browser/context.cc:386
#9 0x00007fffeeff2e0d in CefShutdown() () at ../../cef/libcef/browser/context.cc:233
#10 0x000000000041cb36 in CEF::DeinitializeCEF() () at CEFClientApp.cc:260
#11 0x0000000000415651 in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at CEFViewer.cc:125
(gdb) info threads
Id Target Id Frame
* 1 Thread 0x7ffff7f3f6c0 (LWP 24104) "CEFViewer" 0x00007fffef159e37 in operator() () at ../../base/logging.cc:889
2 Thread 0x7fffce081700 (LWP 24118) "sandbox_ipc_thr" 0x00007fffe408f6fd in poll () from /lib64/libc.so.6
3 Thread 0x7fffcd880700 (LWP 24148) "CEFViewer" 0x00007ffff63137c6 in waitpid () from /lib64/libpthread.so.0
4 Thread 0x7fffcd07f700 (LWP 24149) "ThreadPoolServi" 0x00007fffe40988b3 in epoll_wait () from /lib64/libc.so.6
5 Thread 0x7fffcc87e700 (LWP 24150) "ThreadPoolForeg" 0x00007ffff6310438 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
6 Thread 0x7fffcc07d700 (LWP 24151) "ThreadPoolForeg" 0x00007ffff6310438 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
7 Thread 0x7fffcb87c700 (LWP 24152) "Chrome_IOThread" 0x00007fffe40988b3 in epoll_wait () from /lib64/libc.so.6
8 Thread 0x7fffcb07b700 (LWP 24153) "MemoryInfra" 0x00007ffff631008f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
9 Thread 0x7fffca6db700 (LWP 24154) "ThreadPoolForeg" 0x00007ffff6310438 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
10 Thread 0x7fffc9eda700 (LWP 24155) "ThreadPoolForeg" 0x00007ffff6310438 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
11 Thread 0x7fffc96d9700 (LWP 24156) "inotify_reader" 0x00007fffe408f6fd in poll () from /lib64/libc.so.6
12 Thread 0x7fffc8ed8700 (LWP 24157) "ThreadPoolForeg" 0x00007ffff6310438 in pthread_cond_timedwait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
13 Thread 0x7fffc86d7700 (LWP 24158) "CompositorTileW" 0x00007ffff631008f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
14 Thread 0x7fffc7eb6700 (LWP 24159) "VideoCaptureThr" 0x00007ffff631008f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
15 Thread 0x7fffc76b5700 (LWP 24160) "ThreadPoolSingl" 0x00007ffff631008f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
16 Thread 0x7fffc6eb4700 (LWP 24162) "ThreadPoolSingl" 0x00007ffff631008f in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
17 Thread 0x7fffc61c8700 (LWP 24167) "CacheThread_Blo" 0x00007fffe40988b3 in epoll_wait () from /lib64/libc.so.6


We encounter this problem since we have updgraded CEF from 3.2275 to 93.1.11 and we are doing nothing special with the global request context within our implementation. cefsimple does not crash on exit. Any suggestion would be very appreciated.
Last edited by olzzen on Thu Sep 16, 2021 6:46 am, edited 1 time in total.
olzzen
Techie
 
Posts: 46
Joined: Fri Oct 23, 2015 1:01 am

Re: Crash when calling CefShutdown on Linux

Postby magreenblatt » Wed Sep 15, 2021 5:15 am

Does the crash reproduce with `cefclient --external-message-pump`? Are you calling CefDoMessageLoopWork multiple times before CefShutdown? See also viewtopic.php?f=6&t=18130&p=47876
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Crash when calling CefShutdown on Linux

Postby olzzen » Wed Sep 15, 2021 6:42 am

We currently can't compile cefclient because of missing gtk3.
We have tried up to 10 calls of CefDoMessageLoopWork without any luck.

In another thread we saw the following and tried it out:
https://www.magpcss.org/ceforum/viewtopic.php?f=6&t=17669&start=10
Code: Select all
 bool closed = false;
      while (!closed) {
         closed = browser_->GetHost()->TryCloseBrowser();
         CefDoMessageLoopWork();
      }
      delete browser_;

Again, no luck.

We create only one browser-object, at least the ClientHandler::OnAfterCreated get called only one time.
olzzen
Techie
 
Posts: 46
Joined: Fri Oct 23, 2015 1:01 am

Re: Crash when calling CefShutdown on Linux

Postby olzzen » Thu Sep 16, 2021 2:20 am

Tested with 'cefclient --external-message-pump' on a different hardware with different linux distribution, the problem didn't occur.
olzzen
Techie
 
Posts: 46
Joined: Fri Oct 23, 2015 1:01 am

Re: Crash when calling CefShutdown on Linux

Postby olzzen » Thu Sep 16, 2021 3:35 am

We have solved the problem. But it seems a little weird...

In our ClientHandler::OnBeforeClose there was a pointer comparison as follows:
Code: Select all
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
    CEF_REQUIRE_UI_THREAD();
    base::AutoLock lock_scope(_lock);

    if (--ClientHandler::_browserCount == 0)
    {
        if (_browser == browser) // This test surprisingly fails.
          _browser = nullptr;

        emit signalBrowserClosed();
    }
}


The pointer comparison surprisingly fails. We thought there was only one browser created as ClientHandler::OnAfterCreated gets called only one time. We dumped the pointers in different functions and recognized more than one different pointer addresses.
How can this be explained?

BTW: We don't need to call CefDoMessageLoopWork more than one time before calling CefShutdown.
olzzen
Techie
 
Posts: 46
Joined: Fri Oct 23, 2015 1:01 am

Re: Crash when calling CefShutdown on Linux

Postby magreenblatt » Thu Sep 16, 2021 4:26 am

You can't compare pointers because of the way objects are wrapped when passed across the C/C++ API boundary. Use CefBrowser::IsSame or compare CefBrowser::GetIdentifier instead.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Crash when calling CefShutdown on Linux

Postby olzzen » Thu Sep 16, 2021 4:37 am

magreenblatt wrote:You can't compare pointers because of the way objects are wrapped when passed across the C/C++ API boundary. Use CefBrowser::IsSame or compare CefBrowser::GetIdentifier instead.


Ok, we were not aware of that, because the scoped pointer has a comparison operator, we thought it's usage is save...
Another observation is, that the RenderHandler::OnBrowserDestroyed is not being called. Why is that?
olzzen
Techie
 
Posts: 46
Joined: Fri Oct 23, 2015 1:01 am

Re: Crash when calling CefShutdown on Linux

Postby magreenblatt » Thu Sep 16, 2021 4:58 am

olzzen wrote:
magreenblatt wrote:You can't compare pointers because of the way objects are wrapped when passed across the C/C++ API boundary. Use CefBrowser::IsSame or compare CefBrowser::GetIdentifier instead.


Ok, we were not aware of that, because the scoped pointer has a comparison operator, we thought it's usage is save...
Another observation is, that the RenderHandler::OnBrowserDestroyed is not being called. Why is that?

Chromium terminates render processes ASAP when they're no longer needed. Shutdown-related code in the renderer process won't be executed in that case.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 27 guests