Skip to content

Commit 165d709

Browse files
committed
invert retrycount
1 parent 7b4698b commit 165d709

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

client/src/main/java/dev/snowdrop/buildpack/docker/ImageUtils.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static class ImageInfo {
3838
/**
3939
* Util method to pull images, configure behavior via dockerconfig.
4040
*/
41+
@SuppressWarnings("resource")
4142
public static void pullImages(DockerConfig config, String... imageNames) {
4243
Set<String> imageNameSet = new HashSet<>(Arrays.asList(imageNames));
4344

@@ -65,7 +66,7 @@ public static void pullImages(DockerConfig config, String... imageNames) {
6566
}
6667
}
6768

68-
int retriesRemaining = config.getPullRetryCount();
69+
int retryCount = 0;
6970
Map<String,PullImageResultCallback> pircMap = new HashMap<>();
7071

7172
// pull the images still in set.
@@ -79,15 +80,15 @@ public static void pullImages(DockerConfig config, String... imageNames) {
7980
// wait for pulls to complete.
8081
RuntimeException lastSeen = null;
8182
boolean allDone = false;
82-
while(!allDone && retriesRemaining>=0){
83+
while(!allDone && retryCount<=config.getPullRetryCount()){
8384
allDone = true;
85+
long thisWait = config.getPullTimeout()+(retryCount*config.getPullRetryIncrease());
8486
for (Entry<String, PullImageResultCallback> e : pircMap.entrySet()) {
8587
boolean done = false;
8688
try {
8789
if(e.getValue()==null) continue;
88-
log.debug("waiting on image "+e.getKey());
89-
int extraWait = (config.getPullRetryCount() - retriesRemaining)*config.getPullRetryIncrease();
90-
done = e.getValue().awaitCompletion(config.getPullTimeout() + extraWait, TimeUnit.SECONDS);
90+
log.debug("waiting on image "+e.getKey()+" for "+thisWait+" seconds");
91+
done = e.getValue().awaitCompletion( thisWait, TimeUnit.SECONDS);
9192
log.debug("success for image "+e.getKey());
9293
} catch (InterruptedException ie) {
9394
throw BuildpackException.launderThrowable(ie);
@@ -107,13 +108,13 @@ public static void pullImages(DockerConfig config, String... imageNames) {
107108
e.setValue(null);
108109
}
109110
}
110-
if(retriesRemaining>0){
111+
retryCount++;
112+
if(retryCount<=config.getPullRetryCount()){
111113
if(lastSeen!=null){
112114
log.debug("Error during pull "+lastSeen.getMessage());
113115
}
114-
log.debug("Retrying ("+retriesRemaining+") for "+pircMap.entrySet().stream().filter(e -> e.getValue()!=null).collect(Collectors.toList()));
116+
log.debug("Retrying ("+retryCount+") for "+pircMap.entrySet().stream().filter(e -> e.getValue()!=null).collect(Collectors.toList()));
115117
}
116-
retriesRemaining-=1;
117118
}
118119

119120
if(lastSeen!=null && !allDone){

0 commit comments

Comments
 (0)