From c30fe2b3cfb2eba78eb426a4b1827f1e88c67379 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Wed, 2 Oct 2019 16:41:32 +0300 Subject: [PATCH] log console: do no acquire read action from ProcessListener.processTerminated method (IDEA-216297) GitOrigin-RevId: 52cefa9d9b0e90f80f16ca786e15b71ab4bfbaf3 --- .../diagnostic/logging/LogConsoleBase.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java index 5371b93fb150..ba8454dc2e73 100644 --- a/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java +++ b/platform/lang-impl/src/com/intellij/diagnostic/logging/LogConsoleBase.java @@ -47,6 +47,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.OutputStream; import java.io.Reader; +import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; @@ -298,9 +299,22 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L else { try { final BufferedReader reader = readerThread.myReader; + List lines = new ArrayList<>(); while (reader.ready()) { - //ensure have read lock before requiring for sync, otherwise dispose() under write action would lead to deadlock - ReadAction.run(() -> addMessage(reader.readLine())); + lines.add(reader.readLine()); + } + if (!lines.isEmpty()) { + // If another thread holds the write lock and waits for the process termination + // (i.e. inside `processHandler.waitFor()`), then acquiring the read lock inside + // `ProcessListener.processTerminated` listener method will lead to a deadlock (IDEA-216297). + ApplicationManager.getApplication().executeOnPooledThread(() -> { + //ensure have read lock before requiring for sync, otherwise dispose() under write action would lead to deadlock + ReadAction.run(() -> { + for (String line : lines) { + addMessage(line); + } + }); + }); } } catch (IOException ignore) {}