From 1f1e4db043bc29d85ae274d625c7fd00e3ac439f Mon Sep 17 00:00:00 2001 From: Andrey Vokin Date: Sat, 24 Nov 2018 13:57:41 +0100 Subject: [PATCH] Fixed deadlock in Ruby Remote SDK configuration RubySdkLoadPathInitializer shouldn't block forever, especially when it's under inspection with ReadLock. now it executed with #checkCancelled. RUBY-23085 RM hangs after add new docker-compose sdk in the settings [IDEA-CR-40458] --- .../application/ex/ApplicationUtil.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationUtil.java b/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationUtil.java index 6ad0abf2853f..f0990f5ff012 100644 --- a/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationUtil.java +++ b/platform/core-impl/src/com/intellij/openapi/application/ex/ApplicationUtil.java @@ -62,6 +62,23 @@ public class ApplicationUtil { } }, indicator)); + try { + runWithCheckCanceled(future, indicator); + } + catch (ProcessCanceledException e) { + future.cancel(true); + throw e; + } + return result.get(); + } + + /** + * Waits for {@code future} to be complete, or the current thread's indicator to be canceled + * Note that {@code future} will not be cancelled by this method + */ + public static void runWithCheckCanceled(@NotNull Future future, @NotNull final ProgressIndicator indicator) throws Exception { + final Ref error = Ref.create(); + while (true) { try { indicator.checkCanceled(); @@ -74,7 +91,7 @@ public class ApplicationUtil { try { future.get(25, TimeUnit.MILLISECONDS); ExceptionUtil.rethrowAll(error.get()); - return result.get(); + break; } catch (TimeoutException ignored) { } }