From e464979869b087a1af7c21fa4b54136db563bda4 Mon Sep 17 00:00:00 2001 From: Paul Pazderski Date: Tue, 23 Apr 2019 20:53:36 +0200 Subject: Bug 546641 - [console] ProcessConsole InputReadJob is not cancelable Change-Id: I453380da668bc5d04e2f90469a16d2ce37d1e90d Signed-off-by: Paul Pazderski Signed-off-by: Andrey Loskutov --- .../internal/ui/views/console/ProcessConsole.java | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'org.eclipse.debug.ui/ui') diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java index 0af92d15a..085cb0f80 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/console/ProcessConsole.java @@ -707,11 +707,32 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe private IStreamsProxy streamsProxy; + /** + * The {@link InputStream} this job is currently reading from or maybe blocking + * on. May be null. + */ + private InputStream readingStream; + InputReadJob(IStreamsProxy streamsProxy) { super("Process Console Input Job"); //$NON-NLS-1$ this.streamsProxy = streamsProxy; } + @Override + protected void canceling() { + super.canceling(); + if (readingStream != null) { + // Close stream or job may not be able to cancel. + // This is primary for IOConsoleInputStream because there is no guarantee an + // arbitrary InputStream will release a blocked read() on close. + try { + readingStream.close(); + } catch (IOException e) { + DebugUIPlugin.log(e); + } + } + } + @Override public boolean belongsTo(Object family) { return ProcessConsole.class == family; @@ -723,12 +744,12 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe try { byte[] b = new byte[1024]; int read = 0; - while (read >= 0) { - InputStream input = fInput; - if (input == null) { + while (read >= 0 && !monitor.isCanceled()) { + readingStream = fInput; + if (readingStream == null) { break; } - read = input.read(b); + read = readingStream.read(b); if (read > 0) { String s; if (encoding != null) { @@ -742,7 +763,8 @@ public class ProcessConsole extends IOConsole implements IConsole, IDebugEventSe } catch (IOException e) { DebugUIPlugin.log(e); } - return Status.OK_STATUS; + readingStream = null; + return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS; } } -- cgit v1.2.3