From 040bfa75d16c450378860adf29bf67a98dbcc7d3 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Tue, 17 Sep 2024 00:53:41 +0200 Subject: [PATCH] [Bug]: duct-tape:1.0.8 contains a Thread Leak 2nd step: call shutdown() when stopping the container Related to #9227. --- .../java/org/testcontainers/containers/GenericContainer.java | 4 ++++ .../java/org/testcontainers/utility/ducttape/Timeouts.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/src/main/java/org/testcontainers/containers/GenericContainer.java b/core/src/main/java/org/testcontainers/containers/GenericContainer.java index 01e89093a24..cb9fc3394d9 100644 --- a/core/src/main/java/org/testcontainers/containers/GenericContainer.java +++ b/core/src/main/java/org/testcontainers/containers/GenericContainer.java @@ -65,6 +65,7 @@ import org.testcontainers.utility.TestcontainersConfiguration; import org.testcontainers.utility.ducttape.RateLimiter; import org.testcontainers.utility.ducttape.RateLimiterBuilder; +import org.testcontainers.utility.ducttape.Timeouts; import org.testcontainers.utility.ducttape.Unreliables; import java.io.File; @@ -660,6 +661,9 @@ public void stop() { containerId = null; containerInfo = null; } + + // If the Timeouts class was used, it created a Thread we need to close + Timeouts.shutdown(); } /** diff --git a/core/src/main/java/org/testcontainers/utility/ducttape/Timeouts.java b/core/src/main/java/org/testcontainers/utility/ducttape/Timeouts.java index f2aaa89cf8b..4433886b4f9 100644 --- a/core/src/main/java/org/testcontainers/utility/ducttape/Timeouts.java +++ b/core/src/main/java/org/testcontainers/utility/ducttape/Timeouts.java @@ -21,6 +21,10 @@ public Thread newThread(Runnable r) { } }); + public static void shutdown() { + EXECUTOR_SERVICE.shutdown(); + } + /** * Execute a lambda expression with a timeout. If it completes within the time, the result will be returned. * If it does not complete within the time, a TimeoutException will be thrown.