Skip to content

Commit

Permalink
Catch all DockerExecutionExceptions rather than just btrfs ones
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdanfox committed Oct 4, 2016
1 parent 1c6f7a0 commit 0ae550d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import static java.util.stream.Collectors.toList;

import com.google.common.base.Throwables;
import com.palantir.docker.compose.DockerComposeRule;
import com.palantir.docker.compose.configuration.ShutdownStrategy;
import com.palantir.docker.compose.connection.ContainerName;
Expand All @@ -28,22 +27,25 @@ public void shutdown(DockerComposeRule rule) throws IOException, InterruptedExce
List<ContainerName> runningContainers = rule.dockerCompose().ps();

log.info("Shutting down {}", runningContainers.stream().map(ContainerName::semanticName).collect(toList()));
removeContainersCatchingBtrfs(rule, runningContainers);
if (removeContainersCatchingErrors(rule, runningContainers)) {
return;
}

log.debug("First shutdown attempted failed due to btrfs volume error... retrying");
removeContainersCatchingBtrfs(rule, runningContainers);
if (removeContainersCatchingErrors(rule, runningContainers)) {
return;
}

log.warn("Couldn't shut down containers due to btrfs volume error, "
+ "see https://circleci.com/docs/docker-btrfs-error/ for more info.");
}

private void removeContainersCatchingBtrfs(DockerComposeRule rule, List<ContainerName> runningContainers) throws IOException, InterruptedException {
private boolean removeContainersCatchingErrors(DockerComposeRule rule, List<ContainerName> runningContainers) throws IOException, InterruptedException {
try {
removeContainers(rule, runningContainers);
return true;
} catch (DockerExecutionException exception) {
if (!exception.getMessage().contains("Driver btrfs failed to remove")) {
throw Throwables.propagate(exception);
}
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,4 @@ public void after_two_btrfs_failures_we_should_just_log_and_continue() throws Ex
verify(mockDocker, times(2)).rm(anyListOf(String.class));
}

@Test
public void normal_rm_errors_should_be_rethrown() throws Exception {
exception.expectMessage("Some other error");

doThrow(new DockerExecutionException("Some other error")).when(mockDocker).rm(anyListOf(String.class));
ShutdownStrategy.AGGRESSIVE.shutdown(rule);
}

@Test
public void after_a_btrfs_failure_a_real_exception_should_be_rethrown() throws Exception {
exception.expectMessage("real exception");

doThrow(new DockerExecutionException(btrfs_message))
.doThrow(new DockerExecutionException("real exception"))
.when(mockDocker)
.rm(anyListOf(String.class));

ShutdownStrategy.AGGRESSIVE.shutdown(rule);
}

}

0 comments on commit 0ae550d

Please sign in to comment.