From 52a72504996296d0f47d6c7e9d71053b9727ecb1 Mon Sep 17 00:00:00 2001 From: Richard North Date: Sat, 14 Jan 2017 20:46:23 +0000 Subject: [PATCH] Ensure that piped streams are closed automatically. This resolves an apparently deadlock somewhere between netty/docker if a previous test, affected by #263, has failed during copying of a file. --- .../testcontainers/images/builder/ImageFromDockerfile.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java b/core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java index 78cb598d27f..e51e6d003af 100644 --- a/core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java +++ b/core/src/main/java/org/testcontainers/images/builder/ImageFromDockerfile.java @@ -6,6 +6,7 @@ import com.github.dockerjava.api.model.BuildResponseItem; import com.github.dockerjava.core.command.BuildImageResultCallback; import com.google.common.collect.Sets; +import lombok.Cleanup; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; @@ -113,8 +114,8 @@ public void onNext(BuildResponseItem item) { }; // We have to use pipes to avoid high memory consumption since users might want to build really big images - PipedInputStream in = new PipedInputStream(); - PipedOutputStream out = new PipedOutputStream(in); + @Cleanup PipedInputStream in = new PipedInputStream(); + @Cleanup PipedOutputStream out = new PipedOutputStream(in); profiler.start("Configure image"); BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(in);