From cd45476ae165dbbb0b2bee636d9e2ac418ba16f7 Mon Sep 17 00:00:00 2001 From: Artem Bochkarev Date: Mon, 28 Oct 2024 12:42:50 +0400 Subject: [PATCH] IJPL-164884 Shutdown CEF when some subprocess constantly recreates (cherry picked from commit 69146b91cf563fa11dc7dedfb8c3ac84aad50284) IJ-CR-148229 GitOrigin-RevId: f59ba49b1ae019b170b966a09452f6c56b2214b5 --- platform/ui.jcef/jcef/JBCefApp.java | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/platform/ui.jcef/jcef/JBCefApp.java b/platform/ui.jcef/jcef/JBCefApp.java index 4f7d25837deb..3057950f4123 100644 --- a/platform/ui.jcef/jcef/JBCefApp.java +++ b/platform/ui.jcef/jcef/JBCefApp.java @@ -480,14 +480,21 @@ public final class JBCefApp { private static class MyCefAppHandler extends CefAppHandlerAdapter { private final int myGPUCrashLimit; - private int myGPUCrashCounter = 0; + private final int myTotalCrashLimit; + private int myGPULaunchCounter = 0; + private int myLaunchCounter = 0; private boolean myNotificationShown = false; private final String myArgs; MyCefAppHandler(String @Nullable [] args, boolean trackGPUCrashes) { super(args); myArgs = Arrays.toString(args); - myGPUCrashLimit = trackGPUCrashes ? Integer.getInteger("ide.browser.jcef.gpu.infinitecrash.internallimit", 10) : -1; + if (trackGPUCrashes) { + myGPUCrashLimit = Integer.getInteger("ide.browser.jcef.gpu.infinitecrash.internallimit", 10); + myTotalCrashLimit = myGPUCrashLimit*2; + } else { + myGPUCrashLimit = myTotalCrashLimit = -1; + } } @Override @@ -520,12 +527,22 @@ public final class JBCefApp { @Override public void onBeforeChildProcessLaunch(String command_line) { - if (myGPUCrashLimit >= 0 && command_line != null && command_line.contains("--type=gpu-process")) { - if (++myGPUCrashCounter > myGPUCrashLimit && !myNotificationShown) { + ++myLaunchCounter; + if (command_line == null) + return; + + if (command_line.contains("--type=gpu-process")) { + ++myGPULaunchCounter; + if (myGPUCrashLimit >= 0 && myGPULaunchCounter > myGPUCrashLimit && !myNotificationShown) { ApplicationManager.getApplication().executeOnPooledThread(() -> SettingsHelper.showNotificationDisableGPU()); myNotificationShown = true; } } + if (myTotalCrashLimit >= 0) { + if (myLaunchCounter > myTotalCrashLimit) { + ApplicationManager.getApplication().executeOnPooledThread(() -> CefApp.getInstance().dispose()); + } + } } }