log console: do no acquire read action from ProcessListener.processTerminated method (IDEA-216297)

GitOrigin-RevId: 52cefa9d9b0e90f80f16ca786e15b71ab4bfbaf3
This commit is contained in:
Sergey Simonchik
2019-10-02 14:03:13 +00:00
committed by intellij-monorepo-bot
parent 200db76822
commit c30fe2b3cf
@@ -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<String> 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) {}