CEF quits without notifying host

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.

CEF quits without notifying host

Postby markvulf » Thu Apr 12, 2018 11:26 am

Hello,

I've been debugging this strange issue, I was wondering if anyone has any insight/help to figure out what's going on.

Context:
I am hosting CefSharp.Winforms inside a WPF app (via WindowsFormsHost). The parent app is not mine, but loads my DLL, takes my WPF root element and inserts it into its visual tree.
It's a bit convoluted, but that's what I have to work with.

In certain, cases the parent app will recreate the HWND which hosts the WPF container, which cases the WM_CLOSE to be sent to all child windows of that contains (of which CEF window is one of them). When this happens, Cef subprocess terminates without any reason and doesn't notify the CefSharp host (i.e. via ClientHandler::OnRenderProcessTerminated)
So what happens is that my browser output goes blank (because the render subprocess terminated) and it's very difficult for me to detect this condition to recover from it.

The strangest thing is that when I attach WinDbg to the subprocess, and set various breakpoint, such
Code: Select all
libcef!CefBrowserHostImpl::TryCloseBrowser
libcef!CefBrowserPlatformDelegateNativeWin::WndProc
libcef!cef_shutdown

they are never hit. So I can't track down what path it takes to terminate to see if there is an issue with cef not notifying it is going down.

Any ideas/thoughts on how to debug this?

The repro is 100% reliable but complicate because it involves a third party app (Autodesk Revit) which hosts my content and is the culprit for closing the top HWND. But I will try to make a self-contained example to test it out later

Any help and/or ideas would be appreciated, thank you!
Mark
markvulf
Newbie
 
Posts: 3
Joined: Thu Apr 12, 2018 11:15 am

Re: CEF quits without notifying host

Postby magreenblatt » Thu Apr 12, 2018 11:30 am

You should ask on a support channel for CefSharp. If WM_CLOSE is sent to all child windows it seems more likely that the browser will be closed instead of just the sub-process terminating.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: CEF quits without notifying host

Postby markvulf » Thu Apr 12, 2018 12:15 pm

I don't think it's a CefSharp issue. CefSharp responds to the window being reparented (https://github.com/cefsharp/CefSharp/bl ... er.cs#L592) and then calls CefSubprocess to re-parent the actual browser Window. But even taking that call out doesn't change the behavior, so it seems that Cef render process is somehow responding to this situation that is non-standard (e.g. semi-graceful crash).

What's most bewildering is that I can't set any breakpoints while debugging the subprocess (the symbols are loaded and I am using debug version of libcef.dll). Are there any tricks to setting BPs here?

p.s. I also talked to amaitland of CefSharp a bit about this issue (we agreed we should come here for advivce)
markvulf
Newbie
 
Posts: 3
Joined: Thu Apr 12, 2018 11:15 am

Re: CEF quits without notifying host

Postby magreenblatt » Thu Apr 12, 2018 12:43 pm

Did you attach the debugger to the subprocess? Also, I don't know what "calls CefSubprocess to re-parent the actual browser Window" means.
magreenblatt
Site Admin
 
Posts: 12408
Joined: Fri May 29, 2009 6:57 pm

Re: CEF quits without notifying host

Postby amaitland » Thu Apr 12, 2018 11:16 pm

markvulf wrote:
In certain, cases the parent app will recreate the HWND which hosts the WPF container, which cases the WM_CLOSE to be sent to all child windows of that contains (of which CEF window is one of them). When this happens, Cef subprocess terminates without any reason and doesn't notify the CefSharp host (i.e. via ClientHandler::OnRenderProcessTerminated)
So what happens is that my browser output goes blank (because the render subprocess terminated) and it's very difficult for me to detect this condition to recover from it.


The original language you used made it sound like your application was crashing, at least that's what I think of when someone says the subprocess just terminates.

What you are describing sounds more like the sub process is exiting cleanly as the underlying browser has been closed.

Where does WM_CLOSE originate from? Once you start debugging your main application process I expect you'll see `CefBrowserPlatformDelegateNativeWin::WndProc` receive a WM_CLOSE message.

markvulf wrote:The strangest thing is that when I attach WinDbg to the subprocess, and set various breakpoint, such
Code: Select all
libcef!CefBrowserHostImpl::TryCloseBrowser
libcef!CefBrowserPlatformDelegateNativeWin::WndProc
libcef!cef_shutdown



To hit those breakpoints you should be debugging your main application.

markvulf wrote:p.s. I also talked to amaitland of CefSharp a bit about this issue (we agreed we should come here for advivce)


My suggestion to post here was related to the debugging issues you were having. The whole WinForms/WPF aspect has no relevance in CEF terms.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF quits without notifying host

Postby markvulf » Mon Apr 16, 2018 8:36 am

Thank you all.
Yes, I am attached to both the subprocess and the main application and neither of the (shutdown) breakpoints hit, I will look into CefBrowserPlatformDelegateNativeWin::WndProc a bit more tonight.

Where does WM_CLOSE originate from? Once you start debugging your main application process I expect you'll see `CefBrowserPlatformDelegateNativeWin::WndProc` receive a WM_CLOSE message.

I am assuming the WM_CLOSE comes from the application calling DestroyWindow on the host Window that houses the WPF container (which houses the WinFormsHost which, in turn, parents CEF).

What you are describing sounds more like the sub process is exiting cleanly as the underlying browser has been closed.

If this is the case, then why isn't doesn't CefBrowserHostImpl::RenderProcessGone or ClientAdapter::OnRenderProcessTerminated called? I would expect CefSharp to tell me when the browser process goes away.
markvulf
Newbie
 
Posts: 3
Joined: Thu Apr 12, 2018 11:15 am

Re: CEF quits without notifying host

Postby amaitland » Mon Apr 16, 2018 4:28 pm

OnRenderProcessTerminated is for abnormal termination, sounds like it's exiting gracefully.

If you implement ILifeSpanHandler is DoClose called?

http://cefsharp.github.io/api/63.0.0/ht ... oClose.htm
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am

Re: CEF quits without notifying host

Postby salvadordf » Tue Apr 17, 2018 3:09 am

This is probably not the same case but popup browsers close automatically if the parent is destroyed before the browser creation completes, indicated by a call to OnAfterCreated.
Maintainer of the CEF4Delphi, WebView4Delphi, WebUI4Delphi and WebUI4CSharp projects.
User avatar
salvadordf
Expert
 
Posts: 129
Joined: Sun Dec 18, 2016 8:39 am
Location: Spain


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 49 guests