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 468f61cb1e..4066222010 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 @@ -92,12 +92,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; @@ -108,6 +110,8 @@ public class DeleteAllKeysInList implements ClearListStrategy, ClearContainerStr } retryHandler.imposeBackoffExponentialDelay(numErrors, message); continue; + } finally { + listFuture.cancel(true); } // recurse on subdirectories @@ -163,7 +167,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);