{"record":{"id":"4f2b4df77e76386d","repo":"testcontainers/testcontainers-java","slug":"failed-to-detect-protocol-via-curl","errorCode":null,"errorMessage":"Failed to detect protocol via curl","messagePattern":"Failed to detect protocol via curl","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/ElasticsearchContainer.java","lineNumber":339,"sourceCode":"            httpResult =\n                execInContainer(\n                    \"curl\",\n                    \"-sS\",\n                    \"--connect-timeout\",\n                    \"2\",\n                    \"--max-time\",\n                    \"4\",\n                    \"-o\",\n                    \"/dev/null\",\n                    \"-w\",\n                    \"%{http_code}\",\n                    \"http://localhost:\" + ELASTICSEARCH_DEFAULT_PORT + \"/\"\n                );\n            if (httpResult.getExitCode() == 0 && !\"000\".equals(httpResult.getStdout().trim())) {\n                return \"http\";\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"Failed to detect protocol via curl\", e);\n        }\n\n        throw new RuntimeException(\n            String.format(\n                \"Failed to detect protocol via curl. Both HTTPS and HTTP probes failed. \" +\n                \"HTTPS probe - exit code: %d, stdout: %s, stderr: %s; \" +\n                \"HTTP probe - exit code: %d, stdout: %s, stderr: %s\",\n                httpsResult.getExitCode(),\n                httpsResult.getStdout(),\n                httpsResult.getStderr(),\n                httpResult.getExitCode(),\n                httpResult.getStdout(),\n                httpResult.getStderr()\n            )\n        );\n    }\n\n    // The TransportClient will be removed in Elasticsearch 8. No need to expose this port anymore in the future.","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/ElasticsearchContainer.java#L321-L357","documentation":"ElasticsearchContainer.getHttpScheme() probes the running container by executing curl (HTTPS then HTTP) against localhost:9200 inside the container to determine which scheme the node is serving. This RuntimeException wraps any exception thrown while executing those probes (e.g. container exec failure). A sibling error reports probe results when both probes complete but fail.","triggerScenarios":"Calling getHttpScheme()/getHttpHostAddress()/url/scheme when execInContainer(\"curl\", ...) throws — e.g. container stopped mid-probe, exec API failure, or curl missing from the image.","commonSituations":"Custom/minimal Elasticsearch images without curl installed; container stopped or paused by resource pressure between readiness checks and the probe; Docker engine issues during exec.","solutions":["Ensure the container image contains a curl binary (testcontainers images include it; custom images may not).","Wait for the container to be running/ready (waitingFor(Wait.forHttp(...))) before calling getHttpScheme().","Check the wrapped cause (RuntimeException.getCause()) for the actual exec failure and fix the underlying Docker/container issue.","Upgrade the Elasticsearch container image to an official Testcontainers-supported one."],"exampleFix":"// before\nString scheme = container.getHttpScheme(); // may throw\n// after\nif (container.isRunning()) {\n    String scheme = container.getHttpScheme();\n}","handlingStrategy":"try-catch","validationCode":"if (!container.isRunning()) { throw new IllegalStateException(\"Container must be running before getHttpScheme()\"); }","typeGuard":null,"tryCatchPattern":"try { String scheme = container.getHttpScheme(); } catch (RuntimeException e) { LOG.error(\"curl protocol probe failed; check image has curl and container is alive\", e.getCause()); throw e; }","preventionTips":["Use official testcontainers Elasticsearch images that ship curl.","Configure a wait strategy before querying the scheme.","Never call getHttpScheme() after stopping the container.","Log the cause chain — the wrapped exception explains the exec failure."],"tags":["elasticsearch","testcontainers","container-exec","protocol-detection"],"backgroundTag":"http-request-failed","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"}