CefSharp.BrowserSubprocess.exe left running after parent process exit

Created on 13 Apr 2018  路  27Comments  路  Source: cefsharp/CefSharp

  • What version of the product are you using?

    • 65 but happens in previous versions also at least since 57
  • What architecture x86 or x64?

    • Happens in both architecures
  • On what operating system?

    • Win10
  • Are you using WinForms, WPF or OffScreen?

    • WPF
  • What steps will reproduce the problem?

    • I don't know how to reproduce but it happens frequently
  • What is the expected output? What do you see instead?

    • CefSharp.BrowserSubprocess.exe does not close and keeps around consuming 100% of 1 CPU core after the main application process closed
  • Please provide any additional information below.

    • The stack trace of the process main thread consuming the CPU:
      0, libcef.dll!IsSandboxedProcess+0x19a0bac
      1, 0xfbe730088e478a
      2, 0xc9f26501c193b3a
      3, 0x4107d6671bc664d4
      4, 0x4107d6671c193b3a
      5, 0x4107d6671bc664d4
      6, libcef.dll!IsSandboxedProcess+0x19a0bac (No unwind info)
      7, libcef.dll!cef_zip_reader_create+0x1042499 (No unwind info)
      8, libcef.dll!cef_zip_reader_create+0x104201a (No unwind info)
      9, libcef.dll!RelaunchChromeBrowserWithNewCommandLineIfNeeded+0x17869 (No unwind info)
      10, libcef.dll!GetHandleVerifier+0x408c9 (No unwind info)
      11, libcef.dll!cef_zip_reader_create+0x10458b3 (No unwind info)
      12, libcef.dll!IsSandboxedProcess+0x1448bb3 (No unwind info)
      13, libcef.dll!GetHandleVerifier+0x408c9 (No unwind info)
      14, libcef.dll!GetHandleVerifier+0x5b023 (No unwind info)
      15, libcef.dll!GetHandleVerifier+0x9206 (No unwind info)
      16, libcef.dll!GetHandleVerifier+0x9547 (No unwind info)
      17, libcef.dll!GetHandleVerifier+0x965e (No unwind info)
      18, libcef.dll!GetHandleVerifier+0x5cea7 (No unwind info)
      19, libcef.dll!GetHandleVerifier+0x8f4f (No unwind info)
      20, libcef.dll!cef_time_delta+0x997ff (No unwind info)
      21, libcef.dll!IsSandboxedProcess+0xfc1383 (No unwind info)
      22, libcef.dll!cef_zip_reader_create+0x10d9bf3 (No unwind info)
      23, libcef.dll!cef_zip_reader_create+0x10da00c (No unwind info)
      24, libcef.dll!IsSandboxedProcess+0x49d33 (No unwind info)
      25, libcef.dll!IsSandboxedProcess+0x4a19b (No unwind info)
      26, libcef.dll!cef_zip_reader_create+0x10d9b1f (No unwind info)
      27, libcef.dll!cef_zip_reader_create+0x10e625f (No unwind info)
      28, libcef.dll!cef_execute_process+0x56 (No unwind info)
      29, CefSharp.BrowserSubprocess.Core.dll!CefSharp::CefAppUnmanagedWrapper::OnContextCreated+0x16f3b (No unwind info)
      30, DomainBoundILStubClass.IL_STUB_PInvoke(CefMainArgs, scoped_refptr, Void*) + 0xcc <-- 0x3496804 (No unwind info)
      31, CefSharp.BrowserSubprocess.SubProcess.Run() + 0xda <-- 0x34966da (No unwind info)
      32, CefSharp.BrowserSubprocess.Program.Main(System.String[]) + 0xeb <-- 0x349536b (No unwind info)
      33, clr.dll+0xeb16 (No unwind info)
      34, clr.dll!LogHelp_TerminateOnAssert+0x5884 (No unwind info)
      35, clr.dll!LogHelp_TerminateOnAssert+0x6d14 (No unwind info)
      36, clr.dll!CorExeMain+0x182c (No unwind info)
      37, clr.dll!GetMetaDataPublicInterfaceFromInternal+0xaf30 (No unwind info)
      38, clr.dll!GetMetaDataPublicInterfaceFromInternal+0xb6a6 (No unwind info)
      39, clr.dll!GetMetaDataPublicInterfaceFromInternal+0xb749 (No unwind info)
      40, clr.dll!GetMetaDataPublicInterfaceFromInternal+0xb0a6 (No unwind info)
      41, clr.dll!CorExeMain+0x1c (No unwind info)
      42, mscoreei.dll!CorExeMain+0x7b (No unwind info)
      43, mscoree.dll!DllUnregisterServer+0x169 (No unwind info)
      44, mscoree.dll!CorExeMain+0x8 (No unwind info)
      45, ntdll.dll!RtlGetAppContainerNamedObjectPath+0x137 (No unwind info)
      46, ntdll.dll!RtlGetAppContainerNamedObjectPath+0x107 (No unwind info)
  • Does the cef log provide any relevant information? (By default there should be a debug.log file in your bin directory)

    • Logs are off
  • Any other background information that's relevant? Are you doing something out of the ordinary? 3rd party controls?

    • No third-parties

Most helpful comment

Spawning a thread to monitor the parent process exiting and close the subprocess, set 'CefSharpSettings.SubprocessExitIfParentProcessClosed = true' before calling Cef.Initialize.

See https://github.com/cefsharp/CefSharp/commit/e4535ab9dfea229eb26ad00b910ecdc3e883fd0f

All 27 comments

What type of process is it that's still running?
How are you calling Cef.Shutdown?

Enable logging to see if there are any clues.

I got a dangling renderer process.
Enabling the logs the only error I got there was:

[0417/163721.782:ERROR:broker_win.cc(134)] Error sending sync broker message

Regarding Shutdown I'm doing on Application Exit. I even removed browsers dispose and shutdown to see if these were being missed sometimes, but removing those does not leave any cefsharp sub processes around when the app exits. Even if I kill the main app (but not the sub processes) the sub processes go away.

I managed to reproduce the problem consistently, even with the CeSharpWpfExample.
Steps:
1) Open the the app or a new tab
2) Wait for the CefSubprocess to be created
3) Close the app right away (its easier when debugging and you stop debugging)

At least one renderer type subprocess will be laying around.
It seems that if you don't wait for "complete" initialization the subprocess will fail to exit gracefully.

Please provide more detail in the list of steps to reproduce.

I'm not seeing any processing lingering when using a x86 Release build executed outside of Visual Studio. Tried closing with File->Exit and using the X and everything releases normally. Tested with commit https://github.com/cefsharp/CefSharp/commit/9eb19756ac8791f3bc716629d9a01a0f8d6c5990

To able to reproduce easily I changed the BrowserTabViewModel.cs and inserted the following:

WebBrowser.FrameLoadStart += (s, args) => Process.GetCurrentProcess().Kill();
WebBrowser.FrameLoadEnd += (s, args) =>

If you run in Release mode (tried x64) outside of VS it will leave a lingering CefSharp.Subprocess. This is not exactly the behavior I'm experiencing most of the times, cause this process just stays there without consuming CPU, when most of the times I get a lingering process consuming lots of CPU cycles.

My guess is that CefSharp.Subprocess is not prepared to handle situations where the main process dies or aborts browser creation (?) during its initialization.

You have to call Cef.Shutdown to cleanly exit and terminate the child processes, a dirty exit like Process.Kill is always going to be problematic.

A lingering process consuming lots of CPU is very different scenario. Did you search the CEF forum to see if others are having problems?

Yes, I did a previous search in CEF forums before posting here.... but no luck.

Of course I'm not using Process.Kill in my application, this was only a way (I found) to demonstrate the behavior. Again this is a time-sensitive problem that is not easily reproducible, although I get it very often on my App (with thousands of users).

To workaround this problem, I had to create a watchdog (https://github.com/OutSystems/WebView/blob/master/WebViewWatcher/Program.cs) process (launched when cef is initialized) that waits for the main process to exit (or die) and then checks if there are any lingering cefsharp processes, and kills them. I'm not happy with the workaround, but it works. I would like that cefsharp could handle these scenarios.

Process termination is completely in the hands of CEF/Chromium. It's possible CefSharp isn't releasing all references to some of the CEF objects. Closing a browser instance can be quite complicated, it's possible the Dispose implementation can be improved, see http://magpcss.org/ceforum/apidocs3/projects/(default)/CefLifeSpanHandler.html#DoClose(CefRefPtr)

From a .net perspective, the WPF dispose/finalize implementation needs some work to make it match the .net blueprint, thought it's unclear if that would be beneficial in this scenario.

I've seen other reports of processes not terminating, I'm sure I'd find more of I kept looking.

http://magpcss.org/ceforum/viewtopic.php?f=6&t=15817&p=37632
http://magpcss.org/ceforum/viewtopic.php?f=6&t=15413

http://magpcss.org/ceforum/viewtopic.php?f=6&t=15817&start=10#p37820

This one has a workaround (very similar to the one I implemented). Are you open to the introduction of this workaround? Is it worth working on a pull request?

In theory it sounds reasonable, you can obtain the parent process id from the command line as it's already being passed through.

https://github.com/cefsharp/CefSharp/blob/cefsharp/63/CefSharp.BrowserSubprocess.Core/WcfEnabledSubProcess.h#L30

If we are going to go down that path then I'd prefer the code was added to CefSharp.BrowserSubprocess.exe, if it turns out not to suite some usage scenario someone can implement their own sub process without the code.

2375 has been merged, a command line arg will be added to make this optional, once further testing has been completed it can be turned on by default

Spawning a thread to monitor the parent process exiting and close the subprocess, set 'CefSharpSettings.SubprocessExitIfParentProcessClosed = true' before calling Cef.Initialize.

See https://github.com/cefsharp/CefSharp/commit/e4535ab9dfea229eb26ad00b910ecdc3e883fd0f

I've recently also seen this issue in 65-pre when I had multiple tabs (100+) open and exited the application from Visual Studio debug, reproduced with the minimal example (extended to include tabs). I then upgraded to 67.0.0-CI2649 and added the command line arg CefSharpSettings.SubprocessExitIfParentProcessClosed = true
before calling Cef.Initialize but the problem still exists.

What can I provide to make debugging this issue easier?

Test again with commit https://github.com/cefsharp/CefSharp/commit/d09c3e8b031620ec2f32ca873313568147cb7ffe

What can I provide to make debugging this issue easier?

If you still have problems then download the source and add a Debugger.Launch to CefSharp.BrowserSubProcess.Program.cs and step through the code.

d09c3e8 fixes the bug! Thanks @amaitland!

What is the risk/is it possible, to close BrowserSubprocess like what has been done for this issue when calling Cef.Shutdown?

@amaitland I've been playing around some more with the fix and I still seem to have the issue even after upgrading to 65.0.0pre-02. I tracked d09c3e8 and it seems to have made it into pre-02. Am I correct in assuming this?

Regardless I have a fork of the MinimalExample where the issue is reproduced and the following steps required to do it:

1) Run the project in Visual Studio 2017 64x
2) Stop the debugger
3) Run the following command on Powershell:
(get-process cefsharp.browsersubprocess -erroraction 'Ignore').count
4) After a few tries the number of cefsharp.browsersubprocesses when the parent process is closed should be more than 0

Thank you in advance

I tracked d09c3e8 and it seems to have made it into pre-02. Am I correct in assuming this?

@rajdevraj1 No, that's incorrect. It's not part of the -pre02 release. The change has been merged into the cefsharp/65 branch and will be part of the official release.

https://github.com/cefsharp/CefSharp/compare/v65.0.0-pre02...cefsharp/65 lists all the change made since the -pre02 release.

@amaitland damn, well thanks for making that clear and for being so quick. I've just tested this in the latest CI build again and it's fixed.

PS: I didn't know you could compare with the -pre02 that will be helpful in the future

This issue still exists on the latest version (with the subprocess constantly using up to 30-40% CPU after main process exits). Are there plans on how to fix this in the near future?

It is easily reproducible by starting the debugger then stopping it.

It is easily reproducible by starting the debugger then stopping it.

@hristijankiko At what point in your code are you setting CefSharpSettings.SubprocessExitIfParentProcessClosed = true? Before you call Cef.Initialize?

Are there plans on how to fix this in the near future?

An attempt has been made to resolve the problem, at it's core it represents a problem that reproduces in CEF it's self, if the solution we've added doesn't work for you then the only definitive fix would be to have changes made to CEF.

I am using CefSharp.WPF - 73.1.130.
First I tried below

bool ILifeSpanHandler.DoClose(IWebBrowser browserControl, IBrowser browser)
        {
            return false;
        }

this not solved then I came to this issue on github and then I set

 CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
 if (!Cef.IsInitialized)
        Cef.Initialize(WebBrowserSettingsAdapter.MapToCefSettings(WebBrowserSettings));

still doesn't fixed issue.
Could you please provide solution for this?

Does the problem reproduce with version 81.3.100? You can use https://github.com/cefsharp/CefSharp.MinimalExample for testing purposes, it's already updated to the latest supported version.

Version 73.1.130 is old and unsupported.

Taking latest version is breaking changes, still I will try to use latest version at least for testing and update here if I still get issue. Thanks for help.

@amaitland I tried minimal example with latest version of CefSharp.Wpf, sub process got closed perfectly, however I downgraded CefSharp.WPF package from latest to 73.1.130 and with that it also worked perfectly, I mean all sub process got closed.
I was expecting issue will get produced when I downgrade but it didn't.

@amaitland one more observation, its strange but not getting how to fix hence asking.
I logged to my machine with one domain something like xyz\myuser , it doesn't closed my exe, but when I login using PQR\myanotherUser then it closes exe.
Did you get query like this before? How I can fix this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alphamax picture alphamax  路  43Comments

amaitland picture amaitland  路  22Comments

DaZiYuan picture DaZiYuan  路  19Comments

ay2015 picture ay2015  路  31Comments

8 picture 8  路  39Comments