Skip to content

Fix log-related leaks #2883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ public Container.ExecResult execInContainer(InspectContainerResponse containerIn
final ToStringConsumer stdoutConsumer = new ToStringConsumer();
final ToStringConsumer stderrConsumer = new ToStringConsumer();

FrameConsumerResultCallback callback = new FrameConsumerResultCallback();
callback.addConsumer(OutputFrame.OutputType.STDOUT, stdoutConsumer);
callback.addConsumer(OutputFrame.OutputType.STDERR, stderrConsumer);
try (FrameConsumerResultCallback callback = new FrameConsumerResultCallback()) {
callback.addConsumer(OutputFrame.OutputType.STDOUT, stdoutConsumer);
callback.addConsumer(OutputFrame.OutputType.STDERR, stderrConsumer);

dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(callback).awaitCompletion();
dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(callback).awaitCompletion();
}
Integer exitCode = dockerClient.inspectExecCmd(execCreateCmdResponse.getId()).exec().getExitCode();

final Container.ExecResult result = new Container.ExecResult(
Expand Down
18 changes: 12 additions & 6 deletions core/src/main/java/org/testcontainers/utility/ResourceReaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static String start(String hostIpAddress, DockerClient client) {

StringBuilder ryukLog = new StringBuilder();

client.logContainerCmd(ryukContainerId)
ResultCallback.Adapter<Frame> logCallback = client.logContainerCmd(ryukContainerId)
.withSince(0)
.withFollowStream(true)
.withStdOut(true)
Expand Down Expand Up @@ -164,11 +164,17 @@ public void onNext(Frame frame) {
);
kiraThread.setDaemon(true);
kiraThread.start();

// We need to wait before we can start any containers to make sure that we delete them
if (!ryukScheduledLatch.await(TestcontainersConfiguration.getInstance().getRyukTimeout(), TimeUnit.SECONDS)) {
log.error("Timeout out waiting for Ryuk. Ryuk's log:\n{}", ryukLog);
throw new IllegalStateException(String.format("Can not connect to Ryuk at %s:%s", hostIpAddress, ryukPort));
try {
// We need to wait before we can start any containers to make sure that we delete them
if (!ryukScheduledLatch.await(TestcontainersConfiguration.getInstance().getRyukTimeout(), TimeUnit.SECONDS)) {
log.error("Timed out waiting for Ryuk container to start. Ryuk's logs:\n{}", ryukLog);
throw new IllegalStateException(String.format("Could not connect to Ryuk at %s:%s", hostIpAddress, ryukPort));
}
} finally {
try {
logCallback.close();
} catch (IOException ignored) {
}
}

return ryukContainerId;
Expand Down