{"record":{"id":"ccd79ecfe95a0d4e","repo":"testcontainers/testcontainers-java","slug":"timed-out-waiting-for-url-to-be-accessible-s-should-return","errorCode":null,"errorMessage":"Timed out waiting for URL to be accessible (%s should return HTTP %s)","messagePattern":"Timed out waiting for URL to be accessible \\((.+?) should return HTTP (.+?)\\)","errorType":"exception","errorClass":"ContainerLaunchException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java","lineNumber":319,"sourceCode":"                                    String responseBody = getResponseBody(connection);\n\n                                    log.trace(\"Get response {}\", responseBody);\n\n                                    if (!responsePredicate.test(responseBody)) {\n                                        throw new RuntimeException(\n                                            String.format(\"Response: %s did not match predicate\", responseBody)\n                                        );\n                                    }\n                                }\n                            } catch (IOException e) {\n                                throw new RuntimeException(e);\n                            }\n                        });\n                    return true;\n                }\n            );\n        } catch (TimeoutException e) {\n            throw new ContainerLaunchException(\n                String.format(\n                    \"Timed out waiting for URL to be accessible (%s should return HTTP %s)\",\n                    uri,\n                    statusCodes.isEmpty() ? HttpURLConnection.HTTP_OK : statusCodes\n                ),\n                e\n            );\n        }\n    }\n\n    private HttpURLConnection openConnection(final String uri) throws IOException, MalformedURLException {\n        if (tlsEnabled) {\n            final HttpsURLConnection connection = (HttpsURLConnection) new URL(uri).openConnection();\n            if (allowInsecure) {\n                // Create a trust manager that does not validate certificate chains\n                // and trust all certificates\n                final TrustManager[] trustAllCerts = new TrustManager[] {\n                    new X509ExtendedTrustManager() {","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/wait/strategy/HttpWaitStrategy.java#L301-L337","documentation":"HttpWaitStrategy wraps Unreliables.retryUntilTrue and throws ContainerLaunchException when the target URL never became accessible with the expected status within the startup timeout. The TimeoutException is the cause; the message shows the URI and the expected HTTP status(es).","triggerScenarios":"The endpoint never returns an acceptable status code before .withStartupTimeout(...) (default 60s) elapses — wrong port, app crash-looping, or app taking longer than the timeout to start.","commonSituations":"Waiting on a port the container never exposes (missing exposedPorts/Wait.forListeningPort mismatch); JVM/app cold start slower than default timeout; container failed to start at all (check container logs); using https without .usingTls() against a plain-HTTP endpoint.","solutions":["Inspect container logs (container.getLogs()) to see whether the app actually started","Increase the timeout: new HttpWaitStrategy().withStartupTimeout(Duration.ofMinutes(5))","Confirm the port and path are correct and exposed/published","Check Docker resource issues (low memory, slow disk) slowing startup"],"exampleFix":"// before\nnew HttpWaitStrategy().forPort(8080).forPath(\"/health\");\n// after\nnew HttpWaitStrategy().forPort(8080).forPath(\"/health\").withStartupTimeout(Duration.ofMinutes(3));","handlingStrategy":"retry","validationCode":"// Pre-check reachability before starting the wait\nContainerState c = ...;\nif (!c.isRunning()) throw new IllegalStateException(\"Container exited early: \" + c.getLogs());","typeGuard":null,"tryCatchPattern":"try {\n    container.start();\n} catch (ContainerLaunchException e) {\n    if (e.getCause() instanceof TimeoutException) {\n        System.err.println(\"Container logs: \" + container.getLogs());\n    }\n    throw e;\n}","preventionTips":["Increase withStartupTimeout for slow applications","Confirm the port is exposed and the path is correct","Watch container logs during startup to catch crash-loops early"],"tags":["timeout","http","wait-strategy","testcontainers"],"backgroundTag":"request-timeout","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}