From 76a5538229cc7d6ff1b14cbce982afea37fa8d92 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Thu, 1 Nov 2012 17:14:56 -0700 Subject: [PATCH] Cancel Futures in clearContainer This prevents Futures from hanging around on exceptional code paths like interrupts and timeouts. --- .../strategy/internal/DeleteAllKeysInList.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java index b93c652462..acc188f79c 100644 --- a/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java +++ b/blobstore/src/main/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInList.java @@ -91,12 +91,14 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr if (options.isRecursive()) message = message + " recursively"; Map exceptions = Maps.newHashMap(); - PageSet listing; int maxErrors = 3; // TODO parameterize for (int numErrors = 0; numErrors < maxErrors; ) { // fetch partial directory listing + PageSet listing; + Future> listFuture = + connection.list(containerName, options); try { - listing = connection.list(containerName, options).get(); + listing = listFuture.get(); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); break; @@ -107,6 +109,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr } retryHandler.imposeBackoffExponentialDelay(numErrors, message); continue; + } finally { + listFuture.cancel(true); } // recurse on subdirectories @@ -162,7 +166,12 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr } retryHandler.imposeBackoffExponentialDelay(numErrors, message); continue; + } finally { + for (Future future : responses.values()) { + future.cancel(true); + } } + if (!exceptions.isEmpty()) { ++numErrors; retryHandler.imposeBackoffExponentialDelay(numErrors, message);