{"record":{"id":"8fb4c26454e98f40","repo":"testcontainers/testcontainers-java","slug":"could-not-control-proxy","errorCode":null,"errorMessage":"Could not control proxy","messagePattern":"Could not control proxy","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/toxiproxy/src/main/java/org/testcontainers/containers/ToxiproxyContainer.java","lineNumber":200,"sourceCode":"        }\n\n        /**\n         * Cuts the connection by setting bandwidth in both directions to zero.\n         * @param shouldCutConnection true if the connection should be cut, or false if it should be re-enabled\n         */\n        public void setConnectionCut(boolean shouldCutConnection) {\n            try {\n                if (shouldCutConnection) {\n                    toxics().bandwidth(CUT_CONNECTION_DOWNSTREAM, ToxicDirection.DOWNSTREAM, 0);\n                    toxics().bandwidth(CUT_CONNECTION_UPSTREAM, ToxicDirection.UPSTREAM, 0);\n                    isCurrentlyCut = true;\n                } else if (isCurrentlyCut) {\n                    toxics().get(CUT_CONNECTION_DOWNSTREAM).remove();\n                    toxics().get(CUT_CONNECTION_UPSTREAM).remove();\n                    isCurrentlyCut = false;\n                }\n            } catch (IOException e) {\n                throw new RuntimeException(\"Could not control proxy\", e);\n            }\n        }\n    }\n}\n","sourceCodeStart":182,"sourceCodeEnd":205,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/toxiproxy/src/main/java/org/testcontainers/containers/ToxiproxyContainer.java#L182-L205","documentation":"ToxiProxyContainer.setConnectionCut() toggles connection-cutting toxics on the proxy via the toxiproxy HTTP client. Any IOException while adding/removing the toxic wrappers is wrapped in a RuntimeException with the message 'Could not control proxy', so the test fails loudly rather than silently leaving proxy state ambiguous.","triggerScenarios":"Calling setConnectionCut(true/false) when the toxiproxy server has dropped, the container's proxy was removed/recreated, or the underlying proxy API connection fails with an IOException.","commonSituations":"Tests that cut connections under load; toxiproxy container being stopped concurrently; proxy registered under a name that no longer exists on the toxiproxy server; Docker network hiccups between test and toxiproxy container.","solutions":["Check toxiproxy container is running and reachable before toggling cut state","Ensure the proxy is still registered (proxy name unchanged) and its toxics CUT_CONNECTION_DOWNSTREAM/UPSTREAM exist","Catch the RuntimeException and retry after re-establishing the proxy if the test tolerates transient control-plane failures","Verify Docker network connectivity and that the toxiproxy port mapping is exposed"],"exampleFix":"// before\ncontainer.getProxy(x).setConnectionCut(true);\n// after\nif (container.isRunning()) {\n    container.getProxy(x).setConnectionCut(true);\n}","handlingStrategy":"retry","validationCode":"if (!toxiproxyContainer.isRunning()) throw new IllegalStateException(\"toxiproxy container not running\");","typeGuard":null,"tryCatchPattern":"try { proxy.setConnectionCut(true); } catch (RuntimeException e) { /* retry once after brief sleep; toxiproxy control-plane hiccup */ }","preventionTips":["Verify toxiproxy container health before toggling cut state","Keep proxy registration names stable across test phases","Avoid stopping the toxiproxy container while proxies are mid-toggle"],"tags":["toxiproxy","network","ioexception"],"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-23T08:17:48.524Z"}