Orchid: fix infinite task creation loop when shutting down

This commit is contained in:
Devrandom 2014-08-24 12:49:34 -07:00 committed by Mike Hearn
parent 5be769d4ca
commit de3665f734
3 changed files with 12 additions and 0 deletions

View File

@ -18,4 +18,6 @@ public interface ConnectionCache {
Connection getConnectionTo(Router router, boolean isDirectoryConnection) throws InterruptedException, ConnectionTimeoutException, ConnectionFailedException, ConnectionHandshakeException;
void close();
boolean isClosed();
}

View File

@ -142,6 +142,11 @@ public class CircuitCreationTask implements Runnable {
}
private void buildCircuitIfNeeded() {
if (connectionCache.isClosed()) {
logger.warning("Not building circuits, because connection cache is closed");
return;
}
final List<StreamExitRequest> pendingExitStreams = circuitManager.getPendingExitStreams();
final List<PredictedPortTarget> predictedPorts = predictor.getPredictedPortTargets();
final List<ExitTarget> exitTargets = new ArrayList<ExitTarget>();

View File

@ -101,6 +101,11 @@ public class ConnectionCacheImpl implements ConnectionCache, DashboardRenderable
scheduledExecutor.shutdownNow();
}
@Override
public boolean isClosed() {
return isClosed;
}
public Connection getConnectionTo(Router router, boolean isDirectoryConnection) throws InterruptedException, ConnectionTimeoutException, ConnectionFailedException, ConnectionHandshakeException {
if(isClosed) {
throw new IllegalStateException("ConnectionCache has been closed");