Application fails to shutdown in Release builds

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.

Re: Application fails to shutdown in Release builds

Postby magreenblatt » Thu Jan 28, 2016 11:26 am

Don't call CefDoMessageLoopWork or CefRunMessageLoop when setting multi_threaded_message_loop = true. Also, when using multi_threaded_message_loop = true your main application thread is not the CEF UI thread.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Application fails to shutdown in Release builds

Postby PolesApart » Tue Feb 02, 2016 3:03 pm

It seems like I'm hitting this from time to time (I use multithreaded message loop).
It seems like that by the time my main application thread exits it's main loop and calls CefShutdown(), cef wasn't done cleaning up after last OnBeforeClose. As I can't interfere with cef's own message loop nor with system thread scheduling, my "solution" was to put a Sleep(300); after my thread exits it's own message loop but before calling CefShutdown(). As windows non-console applications runs in background and the windows are already closed, no one notices the sleep. But there ough to be some better thread synchronization possibility.

I'm calling both CefInitialize and CefShutdown on the main application thread (from the main() routine, btw), so unless CefShutdown() should belong be called via a callback from it's own ui thread when multithread_message_loop = true and not from the same (main) thread as CefInitialize was called (as documented), then perhaps it's getting confused by some side-effect of the shutdown sequence as I stated above, because after the sleep I failed to caught that error again.
Last edited by PolesApart on Tue Feb 02, 2016 3:10 pm, edited 1 time in total.
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm

Re: Application fails to shutdown in Release builds

Postby magreenblatt » Tue Feb 02, 2016 3:07 pm

PolesApart wrote:It seems like I'm hitting this from time to time (I use multithreaded message loop).
It seems like that by the time my main application thread exits it's main loop and calls CefShutdown(), cef wasn't done cleaning up after last OnBeforeClose. As I can't interfere with cef's own message loop nor with system thread scheduling, my "solution" was to put a Sleep(300); after my thread exits it's own message loop but before calling CefShutdown(). As windows non-console applications runs in background and the windows are already closed, no one notices the sleep. But there ough to be some better thread synchronization possibility.

Does the problem reproduce in cefclient when running with --multi-threaded-message-loop?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Application fails to shutdown in Release builds

Postby PolesApart » Tue Feb 02, 2016 3:33 pm

magreenblatt wrote:Does the problem reproduce in cefclient when running with --multi-threaded-message-loop?

So far I couldn't reproduce it with a custom compiled cefclient.exe (I'm using 3.2526.1347 for this and my application) nor with 3.2526.1366 downloaded from cefbuilds.com

What I noticed is that I can get this:
[0202/182404:WARNING:raw_channel.cc(208)] Shutting down RawChannel with write buffer nonempty

Every time I got the other message (with the failed assertion) on my application (before introducing the sleep), I also got this one before it.

Is there an easy way to find out what's the (native) thread handle/id for cef's own message loop when using multithread message loop? I could WaitForSingleObject() on it instead of sleeping.
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm

Re: Application fails to shutdown in Release builds

Postby magreenblatt » Tue Feb 02, 2016 4:25 pm

PolesApart wrote:
magreenblatt wrote:Does the problem reproduce in cefclient when running with --multi-threaded-message-loop?

So far I couldn't reproduce it with a custom compiled cefclient.exe (I'm using 3.2526.1347 for this and my application) nor with 3.2526.1366 downloaded from cefbuilds.com

What I noticed is that I can get this:
[0202/182404:WARNING:raw_channel.cc(208)] Shutting down RawChannel with write buffer nonempty

Every time I got the other message (with the failed assertion) on my application (before introducing the sleep), I also got this one before it.

Is there an easy way to find out what's the (native) thread handle/id for cef's own message loop when using multithread message loop? I could WaitForSingleObject() on it instead of sleeping.

Does the problem reproduce with CEF Release builds in your application? What is the symbolized call stack?
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Application fails to shutdown in Release builds

Postby PolesApart » Wed Feb 03, 2016 4:10 pm

I've changed quite a few things on application init & shutdown and it seems more stable now. I'm no longer using any sleep.
In case I catch this one again I'll try to save the crash dump and post here. Thanks!
PolesApart
Mentor
 
Posts: 73
Joined: Fri Dec 05, 2014 1:24 pm

Re: Application fails to shutdown in Release builds

Postby digory » Mon Oct 31, 2016 6:19 am

I ran into the same problem. I call CefExecuteProcess from WinMain. If the result code is >= 0, I return, and CefShutdown will not be called in that process. Otherwise, I set multi_threaded_message_loop to true and call CefInitialize. After this, WinMain goes into a custom event loop. Both the browser and the application I'm trying to integrate it into seem to work fine. However, when the custom event loop ends, I call CefShutdown, and the result is an assertion telling me I'm calling it from an invalid thread. I also tried CefPostTask (TID_UI, base::Bind (::CefShutdown));, with the same result.
digory
Expert
 
Posts: 118
Joined: Wed Oct 26, 2016 3:13 am

Re: Application fails to shutdown in Release builds

Postby magreenblatt » Mon Oct 31, 2016 11:31 am

digory wrote:I ran into the same problem. I call CefExecuteProcess from WinMain. If the result code is >= 0, I return, and CefShutdown will not be called in that process. Otherwise, I set multi_threaded_message_loop to true and call CefInitialize. After this, WinMain goes into a custom event loop. Both the browser and the application I'm trying to integrate it into seem to work fine. However, when the custom event loop ends, I call CefShutdown, and the result is an assertion telling me I'm calling it from an invalid thread. I also tried CefPostTask (TID_UI, base::Bind (::CefShutdown));, with the same result.

CefShutdown needs to be called from the same thread that you called CefInitialize on.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Application fails to shutdown in Release builds

Postby digory » Wed Nov 02, 2016 2:36 am

It's on the same thread. I added the following line before calling CefInitialize and CefShutdown:
Code: Select all
DWORD threadId = ::GetCurrentThreadId();

The Windows API call returns the same threadId both time, 9780. When looking at my code, it seems obvious, too, that it must be the same thread. Still, CefShutdown fails with the log message that it's not on a valid thread. It must have something to do with the multi_threaded_message_loop flag.
digory
Expert
 
Posts: 118
Joined: Wed Oct 26, 2016 3:13 am

Re: Application fails to shutdown in Release builds

Postby amaitland » Wed Nov 02, 2016 3:07 am

What is the exact error your getting? Have you downloaded the symbol and obtained a stack trace? What version are you using?

A way to reproduce the problem would be helpful.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1292
Joined: Wed Jan 14, 2015 2:35 am

PreviousNext

Return to Support Forum

Who is online

Users browsing this forum: No registered users and 105 guests