{"record":{"id":"c87ca84f5acde681","repo":"testcontainers/testcontainers-java","slug":"proxy-could-not-be-created","errorCode":null,"errorMessage":"Proxy could not be created","messagePattern":"Proxy could not be created","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/toxiproxy/src/main/java/org/testcontainers/containers/ToxiproxyContainer.java","lineNumber":137,"sourceCode":"     */\n    @Deprecated\n    public ContainerProxy getProxy(String hostname, int port) {\n        String upstream = hostname + \":\" + port;\n\n        return proxies.computeIfAbsent(\n            upstream,\n            __ -> {\n                try {\n                    final int toxiPort = nextPort.getAndIncrement();\n                    if (toxiPort > LAST_PROXIED_PORT) {\n                        throw new IllegalStateException(\"Maximum number of proxies exceeded\");\n                    }\n\n                    final Proxy proxy = client.createProxy(upstream, \"0.0.0.0:\" + toxiPort, upstream);\n                    final int mappedPort = getMappedPort(toxiPort);\n                    return new ContainerProxy(proxy, getHost(), mappedPort, toxiPort);\n                } catch (IOException e) {\n                    throw new RuntimeException(\"Proxy could not be created\", e);\n                }\n            }\n        );\n    }\n\n    @RequiredArgsConstructor(access = AccessLevel.PROTECTED)\n    @Deprecated\n    public static class ContainerProxy {\n\n        private static final String CUT_CONNECTION_DOWNSTREAM = \"CUT_CONNECTION_DOWNSTREAM\";\n\n        private static final String CUT_CONNECTION_UPSTREAM = \"CUT_CONNECTION_UPSTREAM\";\n\n        private final Proxy toxi;\n\n        /**\n         * The IP address that this proxy container may be reached on from the host machine.\n         */","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/toxiproxy/src/main/java/org/testcontainers/containers/ToxiproxyContainer.java#L119-L155","documentation":"ToxiproxyContainer.getProxy delegates proxy creation to the Toxiproxy HTTP client (client.createProxy). Any IOException from that API call is wrapped in this RuntimeException with the original exception as the cause.","triggerScenarios":"client.createProxy(upstream, \"0.0.0.0:<port>\", upstream) throws IOException — Toxiproxy's HTTP API is unreachable, the port is already in use inside the container, or the upstream address is malformed/rejected.","commonSituations":"Calling getProxy before container.start(), port mapping conflicts, Toxiproxy server crashed inside the container, or invalid upstream host/port syntax.","solutions":["Read the cause (getCause) — it contains the real IOException from the Toxiproxy API.","Ensure the container is started before calling getProxy.","Verify the upstream HostAndPort is reachable and correctly formatted.","Check container logs for Toxiproxy server errors and restart the container if the server died."],"exampleFix":"// before\nToxiproxyContainer container = new ToxiproxyContainer(\"ghcr.io/shopify/toxiproxy:2.11.0\");\ncontainer.getProxy(HostAndPort.fromString(\"db:5432\")); // not started\n// after\nToxiproxyContainer container = new ToxiproxyContainer(\"ghcr.io/shopify/toxiproxy:2.11.0\");\ncontainer.start();\ncontainer.getProxy(HostAndPort.fromString(\"db:5432\"));","handlingStrategy":"try-catch","validationCode":"if (!container.isRunning()) throw new IllegalStateException(\"start the ToxiproxyContainer before calling getProxy\");","typeGuard":null,"tryCatchPattern":"try { proxy = toxiproxy.getProxy(upstream); } catch (RuntimeException e) { if (e.getMessage().equals(\"Proxy could not be created\")) { throw new IllegalStateException(\"toxiproxy API call failed\", e.getCause()); } throw e; }","preventionTips":["Always call start() before getProxy().","Validate upstream HostAndPort format before creating proxies.","Inspect getCause() and container logs for the root IOException."],"tags":["toxiproxy","testcontainers","network"],"backgroundTag":"api-request-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}