What version of the product are you using?
What architecture x86 or x64?
On what operating system?
Are you using WinForms, WPF or OffScreen?
What steps will reproduce the problem?
What is the expected output? What do you see instead?
Please provide any additional information below.
Does the cef log provide any relevant information? (By default there should be a debug.log file in your bin directory)
Any other background information that's relevant? Are you doing something out of the ordinary? 3rd party controls?
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.
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.
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?
You'll have to debug to get a better understanding of what's going on.
You can add a call to https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.debugger.launch?view=netcore-3.1#System_Diagnostics_Debugger_Launch to attach the debugging.
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