From 499db3f998e5e05f3f1e5e29cd1ef2e429213187 Mon Sep 17 00:00:00 2001 From: bunnysayzz Date: Fri, 2 Oct 2026 00:37:14 +0530 Subject: [PATCH] Always render the port in the HttpWaitStrategy probe URI buildLivenessUri dropped the port suffix when the mapped check port was 80 (plain HTTP) or 443 (TLS). That elision is only valid when host: really is the mapped service, which cannot be assumed here: with custom WaitStrategyTarget implementations or proxied environments the resolved check port can be 443 while the service is not at https://host/, silently probing the wrong endpoint. An explicit port is also what the "un-map the port for logging" path relies on: URI.getPort() returns -1 when the port is elided, which breaks the exposed-port lookup and trips the "Unexpected error occurred" warning on every wait. Fixes #12096. --- .../containers/wait/strategy/HttpWaitStrategy.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java b/core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java index 59f6d9077fb..3dc46912b1e 100644 --- a/core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java +++ b/core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java @@ -386,12 +386,14 @@ private URI buildLivenessUri(int livenessCheckPort) { final String scheme = (tlsEnabled ? "https" : "http") + "://"; final String host = waitStrategyTarget.getHost(); - final String portSuffix; - if ((tlsEnabled && 443 == livenessCheckPort) || (!tlsEnabled && 80 == livenessCheckPort)) { - portSuffix = ""; - } else { - portSuffix = ":" + livenessCheckPort; - } + // Always render the port explicitly. Dropping the default port + // (80/443) is only valid when host: really is the mapped + // service, which cannot be assumed here (custom WaitStrategyTarget + // implementations, proxied environments, ...). An explicit port is + // also what the "un-map the port for logging" path above relies on: + // URI.getPort() returns -1 when the port is elided, which breaks the + // exposed-port lookup. + final String portSuffix = ":" + livenessCheckPort; return URI.create(scheme + host + portSuffix + path); }