From b4b8ef723f242a0f58d8d3a8cdcfcc2877cf36f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 8 Oct 2009 19:01:40 +0400 Subject: [PATCH] CVS: a bug with timeout for any command --- .../common/CvsExecutionEnvironment.java | 7 +++++++ .../cvsMessages/CvsListenerWithProgress.java | 11 +++++++++++ .../cvsSupport2/javacvsImpl/CvsCommandStopper.java | 11 +++++++++++ .../netbeans/lib/cvsclient/ICvsCommandStopper.java | 2 ++ .../netbeans/lib/cvsclient/RequestProcessor.java | 14 ++++++++++++-- 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/CvsExecutionEnvironment.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/CvsExecutionEnvironment.java index 02fc493b815e..3f144a84154b 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/CvsExecutionEnvironment.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/common/CvsExecutionEnvironment.java @@ -19,6 +19,13 @@ public class CvsExecutionEnvironment { public boolean isAborted() { return false; } + + public boolean isAlive() { + return true; + } + + public void resetAlive() { + } }; private final CvsMessagesListener myListener; diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsListenerWithProgress.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsListenerWithProgress.java index b863dd7c63e0..aee9e9b13fda 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsListenerWithProgress.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/cvsoperations/cvsMessages/CvsListenerWithProgress.java @@ -10,10 +10,20 @@ public class CvsListenerWithProgress extends CvsMessagesAdapter implements ICvsC private ProgressIndicator myProgressIndicator; private String myLastError; private boolean myIndirectCancel; + private boolean myPing; public CvsListenerWithProgress(ProgressIndicator progressIndicator) { myProgressIndicator = progressIndicator; myIndirectCancel = false; + myPing = false; + } + + public boolean isAlive() { + return myPing; + } + + public void resetAlive() { + myPing = false; } public static CvsListenerWithProgress createOnProgress() { @@ -38,6 +48,7 @@ public class CvsListenerWithProgress extends CvsMessagesAdapter implements ICvsC } public boolean isAborted() { + myPing = true; if (myLastError != null) throw new CvsProcessException(myLastError); if (myIndirectCancel) return true; final ProgressIndicator progressIndicator = getProgressIndicator(); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/CvsCommandStopper.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/CvsCommandStopper.java index 52b687332cd7..c1b45eb15f2e 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/CvsCommandStopper.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/javacvsImpl/CvsCommandStopper.java @@ -6,7 +6,18 @@ import org.netbeans.lib.cvsclient.ICvsCommandStopper; * author: lesya */ public class CvsCommandStopper implements ICvsCommandStopper{ + private volatile boolean myPing; + public boolean isAborted() { + myPing = true; return false; } + + public boolean isAlive() { + return myPing; + } + + public void resetAlive() { + myPing = false; + } } diff --git a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/ICvsCommandStopper.java b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/ICvsCommandStopper.java index 799f22143a78..9945573fb82f 100644 --- a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/ICvsCommandStopper.java +++ b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/ICvsCommandStopper.java @@ -18,4 +18,6 @@ package org.netbeans.lib.cvsclient; public interface ICvsCommandStopper { boolean isAborted(); + boolean isAlive(); + void resetAlive(); } diff --git a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/RequestProcessor.java b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/RequestProcessor.java index 809eadcfed3e..589b3fa091a0 100644 --- a/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/RequestProcessor.java +++ b/plugins/cvs/javacvs-src/org/netbeans/lib/cvsclient/RequestProcessor.java @@ -174,7 +174,9 @@ public final class RequestProcessor implements IRequestProcessor { final Future future = Executors.newSingleThreadExecutor().submit(new Runnable() { public void run() { try { + checkCanceled(); sendRequests(requests, connectionStreams, communicationProgressHandler); + checkCanceled(); sendRequest(requests.getResponseExpectingRequest(), connectionStreams); connectionStreams.flushForReading(); @@ -193,12 +195,19 @@ public final class RequestProcessor implements IRequestProcessor { } }); - semaphore.waitFor((long) (1.2 * myTimeout)); + // todo: think more + final long tOut = (myTimeout < 20000) ? 20000 : myTimeout; + while (true) { + semaphore.waitFor(tOut); + if (future.isDone() || future.isCancelled()) break; + if (! commandStopper.isAlive()) break; + commandStopper.resetAlive(); + } if (! ioExceptionRef.isNull()) throw new IOCommandException(ioExceptionRef.get()); if (! commandExceptionRef.isNull()) throw commandExceptionRef.get(); - if ((! future.isDone() && (! future.isCancelled()))) { + if ((! future.isDone() && (! future.isCancelled()) && (! commandStopper.isAlive()))) { future.cancel(true); throw new CommandException(new CommandAbortedException(), "Command execution timed out"); } @@ -275,6 +284,7 @@ public final class RequestProcessor implements IRequestProcessor { final StringBuffer responseBuffer = new StringBuffer(32); for (; ;) { final String responseString = readResponse(connectionStreams.getLoggedReader(), responseBuffer); + checkCanceled(); if (responseString.length() == 0) { return false; }