11package org .testcontainers .utility ;
22
33import com .github .dockerjava .api .command .CreateContainerCmd ;
4+ import java .util .concurrent .atomic .AtomicReference ;
45import lombok .SneakyThrows ;
56import lombok .extern .slf4j .Slf4j ;
67import org .rnorth .ducttape .ratelimits .RateLimiter ;
@@ -78,6 +79,7 @@ private synchronized void maybeStart() {
7879 ryukContainer .start ();
7980
8081 CountDownLatch ryukScheduledLatch = new CountDownLatch (1 );
82+ AtomicReference <IOException > lastConnectException = new AtomicReference <>();
8183
8284 String host = ryukContainer .getHost ();
8385 Integer ryukPort = ryukContainer .getFirstMappedPort ();
@@ -117,7 +119,12 @@ private synchronized void maybeStart() {
117119 }
118120 }
119121 } catch (IOException e ) {
120- log .warn ("Can not connect to Ryuk at {}:{}" , host , ryukPort , e );
122+ if (ryukScheduledLatch .getCount () != 0 ) {
123+ log .debug (CANNOT_CONNECT , host , ryukPort , e );
124+ lastConnectException .set (e );
125+ } else {
126+ log .warn (CANNOT_CONNECT , host , ryukPort , e );
127+ }
121128 }
122129 });
123130 }
@@ -129,7 +136,10 @@ private synchronized void maybeStart() {
129136 // We need to wait before we can start any containers to make sure that we delete them
130137 if (!ryukScheduledLatch .await (TestcontainersConfiguration .getInstance ().getRyukTimeout (), TimeUnit .SECONDS )) {
131138 log .error ("Timed out waiting for Ryuk container to start. Ryuk's logs:\n {}" , ryukContainer .getLogs ());
132- throw new IllegalStateException (String .format ("Could not connect to Ryuk at %s:%s" , host , ryukPort ));
139+ throw new IllegalStateException (String .format ("Could not connect to Ryuk at %s:%s" , host , ryukPort ),
140+ lastConnectException .get ());
133141 }
134142 }
143+
144+ private static final String CANNOT_CONNECT = "Cannot connect to Ryuk at {}:{}" ;
135145}
0 commit comments