salvadordf / CEF4Delphi

CEF4Delphi is an open source project to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC for Windows, Linux and MacOS.
https://www.briskbard.com/forum/
Other
1.19k stars 363 forks source link

TabbedBrowser2 leaves behind an orphan renderer process when main process is killed #513

Closed EricGrange closed 1 month ago

EricGrange commented 1 month ago

Issue happens to TabbedBrowser2 demo, at least from commit e3cd6821c842f27ada58497cdd522f94ddd97868 (CEF 125.0.19) and up to current, for Delphi 10 with a Win32 executable.

If you start the demo, close normally, all child processes are closed.

But if you start the demo, but either kill the main process from the task manager, or from an abort when debugging in the Delphi IDE, then the renderer sub-process is left behind with 100% CPU usage of one core.

The issue doesn't happen for SimpleBrowser2 for instance AFAICT.

I tried commenting the "GlobalCEFApp.ChromeRuntime := True;" line which was the change introduced with 125.0.19 commit, but this had no effect

salvadordf commented 1 month ago

Sometimes Chromium can detect when the application is closing and it will close the child processes automatically.

Applications should follow the destruction steps described in the code comments of the demos and stopping the debug session skips those steps.

CEF 125 has many internal changes and it might have changed the way it detects when the app is closing.

I built TabbedBrowser2 (32 bits) with Delphi 12 and killing the app from the task manager left no orphan processes but stopping the debugger left one process dangling.

I'll leave this issue open for the moment to see if there's some kind of Windows message or event that notifies the app that the debugging session was closed and then follow the destruction steps in order to close the child processes correctly.

EricGrange commented 1 month ago

Erratum: it was from Delphi 12 not Delphi 10 for me

I have tried runs with or without gpu, with or without pre-existing cache folder, no effect AFAICT.

However there seems to be a time sensitivity related to initialization: when starting the TabbedBrowser2, if killing the main process in the first few seconds, there is pretty much always a leftover process. When waiting maybe 15 seconds, there is no more leftover process, even if the browser frame is very active (I tried running webgl experiments and html5 games).

I went back to SimpleBrowser2 demo, and when killing it swiftly, it exhibits the same issue.

So this may be that the render process is not yet ready to detect or react to a kill notification early on, not sure if that's on the Delphi or the CEF side though.

salvadordf commented 1 month ago

CEF/Chromium initialization and the creation of the first browser may take a few seconds for several reasons like proxy detection, antivirus scan, etc.

I will investigate if killing the app at that moment is a supported scenario in CEF.

EricGrange commented 1 month ago

Issue seems to have been fixed by CEF 125.0.22