subprocess does not exit still left open

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.

subprocess does not exit still left open

Postby jiaojiao » Tue Apr 19, 2016 4:42 pm

Hi All,

I have some orphan sub processes which are remains after the application exits.

The call stack looks like this. What would be the reason for the sub processes not stop? In the meantime, how to close the subprocess? So far the subprocess stops when the browser window is destroyed. Are there APIs that we can directly call to stop the render process?

Code: Select all
    ntdll.dll!77d5c7ec()    
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
    KernelBase.dll!760728c3()    
    kernel32.dll!75d77b89()    
>   libcef.dll!base::WaitableEvent::WaitMany(base::WaitableEvent * * events=0xa8006038, unsigned int count=1635612)  Line 87 + 0x12 bytes   
    libcef.dll!sfntly::Lock::Unlock()  Line 46   
    libcef.dll!IPC::SyncChannel::WaitForReply(IPC::SyncChannel::SyncContext * context=0x00209010, base::WaitableEvent * pump_messages_event=0x00000000)  Line 509 + 0x10 bytes   
    libcef.dll!IPC::SyncChannel::Send(IPC::Message * message=0x001faa20)  Line 493 + 0x7 bytes   
    libcef.dll!content::ChildThreadImpl::Send(IPC::Message * msg=0x001faa20)  Line 535   
    libcef.dll!content::RenderThreadImpl::Send(IPC::Message * msg=0x011faa20)  Line 857   
    libcef.dll!CefContentRendererClient::RenderThreadStarted()  Line 448   
    libcef.dll!content::RenderThreadImpl::Init()  Line 567   
    libcef.dll!content::RenderThreadImpl::RenderThreadImpl(scoped_ptr<base::MessageLoop,base::DefaultDeleter<base::MessageLoop> > main_message_loop={...})  Line 471   
    libcef.dll!content::RendererMain(const content::MainFunctionParams & parameters={...})  Line 197   
    libcef.dll!content::RunNamedProcessTypeMain(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & process_type="renderer", const content::MainFunctionParams & main_function_params={...}, content::ContentMainDelegate * delegate=0x0018fcd0)  Line 383 + 0xd bytes   
    libcef.dll!content::ContentMainRunnerImpl::Run()  Line 775 + 0x6 bytes   
    libcef.dll!content::ContentMain(const content::ContentMainParams & params={...})  Line 19 + 0x7 bytes   
    libcef.dll!CefExecuteProcess(const CefMainArgs & args={...}, CefRefPtr<CefApp> application={...}, void * windows_sandbox_info=0x00000000)  Line 94 + 0xc bytes   
    libcef.dll!cef_execute_process(const _cef_main_args_t * args=0x0018feac, _cef_app_t * application=0x007b95a4, void * windows_sandbox_info=0x00000000)  Line 140 + 0x11 bytes   
    cefrenderaaa.exe!CefExecuteProcess(const CefMainArgs & args={...}, CefRefPtr<CefApp> application={...}, void * windows_sandbox_info=0x00000000)  Line 142 + 0x46 bytes   C++
    cefrenderaaa.exe!WinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x001d45fe, int nCmdShow=5)  Line 65 + 0x21 bytes   C++
    cefrenderaaa.exe!__tmainCRTStartup()  Line 589 + 0x35 bytes   C
    cefrenderaaa.exe!WinMainCRTStartup()  Line 414   C


Thanks for all the information and advice,
jiaojiao
jiaojiao
Techie
 
Posts: 44
Joined: Thu Jun 11, 2015 3:24 am

Re: subprocess does not exit still left open

Postby amaitland » Tue Apr 19, 2016 4:54 pm

At what point are you calling `CloseBrowser(bool)`? Are you closing all your browser instances?

apidocs3/projects/%28default%29/CefBrowserHost.html#CloseBrowser%28bool%29

Also at what point are you calling `CefShutdown()`?

If you close all your browsers and call shutdown, the sub processes will close themselves. There is no explicit `API` to manually close them that I'm aware of.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1291
Joined: Wed Jan 14, 2015 2:35 am

Re: subprocess does not exit still left open

Postby fddima » Tue Apr 19, 2016 9:53 pm

It is possible that child processes remains forever due to Chromium's mojo channel bugs.

This is never should happens in normal workflow (I.e. you close all browsers, wait that they closed, call CefShutdown (which also can never return in case of bad things / corruption / abnormal internal threads termination).

The best thingthat you can do, to protect against any this kind issues is integrate browser process monitoring in renderers and forcibly terminate renderer (by self).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: subprocess does not exit still left open

Postby jiaojiao » Wed Apr 20, 2016 1:15 am

fddima wrote:The best thingthat you can do, to protect against any this kind issues is integrate browser process monitoring in renderers and forcibly terminate renderer (by self).


Thanks for your advice.

Can you elaborate more specific about this approach? How can i integrate the monitoring in renders? Are there APIs in the render? The CefShutdown is called from the browser process before application exits. How can I wait for all browsers closed? Waitforobject??

Thanks,
jiaojiao
jiaojiao
Techie
 
Posts: 44
Joined: Thu Jun 11, 2015 3:24 am

Re: subprocess does not exit still left open

Postby jiaojiao » Wed Apr 20, 2016 1:18 am

amaitland wrote:At what point are you calling `CloseBrowser(bool)`? Are you closing all your browser instances?

http://magpcss.org/ceforum/apidocs3/pro ... %28bool%29

Also at what point are you calling `CefShutdown()`?

If you close all your browsers and call shutdown, the sub processes will close themselves. There is no explicit `API` to manually close them that I'm aware of.


Thanks for your reply.

When the control is receiving WM_CLOSE and it will be destroyed, at that moment we call CloseBrowser(True). I know onbeforeclose is called everytime. So I assumed all the browser instances are closed. How can I check all the browser instances are closed or not?

We call CefShutDown just before the application exits.

Are there any problems you found?

Thanks,
jiaojiao
jiaojiao
Techie
 
Posts: 44
Joined: Thu Jun 11, 2015 3:24 am

Re: subprocess does not exit still left open

Postby fddima » Wed Apr 20, 2016 2:52 am

jiaojiao wrote:Thanks for your advice.

Can you elaborate more specific about this approach? How can i integrate the monitoring in renders? Are there APIs in the render? The CefShutdown is called from the browser process before application exits. How can I wait for all browsers closed? Waitforobject??

Thanks,
jiaojiao

I'm just note, that this is not for regular cases. I.e. you normally should not hit in this issue.

More specific:

1. You can assume that browser closed when OnBeforeClose called.

2. About browser monitoring - one of easiest way is pass browser process ID via command line argument. Or create inheritable handle and pass it via command line argument. This can be done in one of cef callbacks, sorry forget just now it is name. It is called before child process spawn and allow add own arguments to renderer. In renderer process you can parse args and obtain process handle (from pid or directly) just wait it for via any appropriate system call (WaitForObject?, I'm long time not touch win32), of course on own thread. To do not spawn additional threads may be one of async wait can be used. And when your's guardian is setted up, you can execute CefExecuteProcess. I'm use exactly this approach, but in my case I'm easily can hit in this issue because sometimes it work in extreme conditions.

UPD: Renderers it self handle this situation. But some TODOs in chromium code prevent to handle this in all cases properly. And at same time this is not an issue for chromium itself, because it is guarded much better by crash handler and may be something other. And regular browser using is far away from extreme conditions.
Last edited by fddima on Wed Apr 20, 2016 3:10 am, edited 1 time in total.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: subprocess does not exit still left open

Postby fddima » Wed Apr 20, 2016 3:05 am

jiaojiao wrote:When the control is receiving WM_CLOSE and it will be destroyed, at that moment we call CloseBrowser(True). I know onbeforeclose is called everytime.


There is exist topic nearby or in CEF issues about. Try don't call CloseBrowser in react of WM_CLOSE/WM_DESTROY events, as it should be closed without your attention (when browser window destroyed). But ensure that OnBeforeClose still called. Hope this helps.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: subprocess does not exit still left open

Postby fddima » Wed Apr 20, 2016 3:08 am

Finally if nothing helps: enable CEF logging and try CEF debug build (if not already). CEF performs some additional checks in CefShutdown, so if you don't free some important object it should let you know about.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: subprocess does not exit still left open

Postby jiaojiao » Fri Apr 22, 2016 6:32 am

fddima wrote:
jiaojiao wrote:Thanks for your advice.

Can you elaborate more specific about this approach? How can i integrate the monitoring in renders? Are there APIs in the render? The CefShutdown is called from the browser process before application exits. How can I wait for all browsers closed? Waitforobject??

Thanks,
jiaojiao

I'm just note, that this is not for regular cases. I.e. you normally should not hit in this issue.

More specific:

1. You can assume that browser closed when OnBeforeClose called.

2. About browser monitoring - one of easiest way is pass browser process ID via command line argument. Or create inheritable handle and pass it via command line argument. This can be done in one of cef callbacks, sorry forget just now it is name. It is called before child process spawn and allow add own arguments to renderer. In renderer process you can parse args and obtain process handle (from pid or directly) just wait it for via any appropriate system call (WaitForObject?, I'm long time not touch win32), of course on own thread. To do not spawn additional threads may be one of async wait can be used. And when your's guardian is setted up, you can execute CefExecuteProcess. I'm use exactly this approach, but in my case I'm easily can hit in this issue because sometimes it work in extreme conditions.

UPD: Renderers it self handle this situation. But some TODOs in chromium code prevent to handle this in all cases properly. And at same time this is not an issue for chromium itself, because it is guarded much better by crash handler and may be something other. And regular browser using is far away from extreme conditions.


Sorry to reply late. Thanks for sharing the information. I am going to have a try.
jiaojiao
Techie
 
Posts: 44
Joined: Thu Jun 11, 2015 3:24 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 35 guests