From 859851db7eecbf01b61064b331b7628e5363c46d Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 15 Mar 2016 00:08:42 +0100 Subject: [PATCH] reliability in non-blocking mode: before terminating read loop make sure all available output is read --- .../src/com/intellij/util/io/BaseDataReader.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/platform/util/src/com/intellij/util/io/BaseDataReader.java b/platform/util/src/com/intellij/util/io/BaseDataReader.java index a1007f7d39e9..f5ac7007a72d 100644 --- a/platform/util/src/com/intellij/util/io/BaseDataReader.java +++ b/platform/util/src/com/intellij/util/io/BaseDataReader.java @@ -125,16 +125,21 @@ public abstract class BaseDataReader { protected void doRun() { try { + boolean stopSignalled = false; while (true) { - boolean read = readAvailable(); + final boolean read = readAvailable(); - if ((!read && isStopped) || mySleepingPolicy == SleepingPolicy.BLOCKING) { - // in non-blocking mode, if we have read something on a previous step, we should check - // if some additional output is available no matter whether the process is already stopped or not + if (stopSignalled || mySleepingPolicy == SleepingPolicy.BLOCKING) { break; } - TimeoutUtil.sleep(mySleepingPolicy.getTimeToSleep(read)); + stopSignalled = isStopped; + + if (!stopSignalled) { + // if process stopped, there is no sense to sleep, + // just check if there is unread output in the stream + TimeoutUtil.sleep(mySleepingPolicy.getTimeToSleep(read)); + } } } catch (IOException e) {