Skip to content

Commit

Permalink
Use exponential backoff when retrying from 10ms to 100ms
Browse files Browse the repository at this point in the history
  • Loading branch information
ewencluley committed Mar 30, 2021
1 parent 64dee37 commit b9708be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/fabric8/maven/docker/service/RunService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.io.File;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -469,8 +470,8 @@ private void startContainer(ImageConfiguration imageConfig, String id, GavLabel

private void updateMappedPortsAndAddresses(String containerId, PortMapping mappedPorts) throws DockerAccessException {
RetryPolicy<Void> retryPolicy = new RetryPolicy<Void>()
.withMaxAttempts(10)
.withDelay(Duration.ofMillis(250))
.withMaxAttempts(20)
.withBackoff(10, 100, ChronoUnit.MILLIS)
.handle(PortBindingException.class)
.onFailedAttempt(f -> log.debug("Failed to update mapped ports for container %s (attempt %d), retrying",
containerId, f.getAttemptCount()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void failAfterRetryingIfInsufficientPortBindingInformation(
new Expectations() {{
docker.createContainer(withAny(new ContainerCreateConfig("img")), anyString); result = "containerId";
portMapping.needsPropertiesUpdate(); result = true;
queryService.getMandatoryContainer("containerId"); result = container; times = 10;
queryService.getMandatoryContainer("containerId"); result = container; times = 20;
container.isRunning(); result = true;
container.getPortBindings(); result = new PortBindingException("5432/tcp", new Gson().fromJson("{\"5432/tcp\": []}", JsonObject.class));
}};
Expand Down

0 comments on commit b9708be

Please sign in to comment.