{"record":{"id":"e259e75675669070","repo":"apache/pulsar","slug":"illegal-broker-host-port-brokerportandhost","errorCode":null,"errorMessage":"Illegal broker host:port '${brokerPortAndHost}'","messagePattern":"Illegal broker host:port '(.+?)'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java","lineNumber":195,"sourceCode":"                        .attr(\"targetAddress\", targetBrokerAddress)\n                        .attr(\"brokerHost\", brokerHostAndPort)\n                        .exception(future.cause())\n                        .log(\"Establishing connection failed. Closing inbound channel.\");\n                Channel channel = f.channel();\n                if (channel != null) {\n                    channel.close();\n                }\n                inboundChannel.close();\n            }\n        });\n    }\n\n    private static String parseHost(String brokerPortAndHost) {\n        int pos = brokerPortAndHost.lastIndexOf(':');\n        if (pos > 0) {\n            return brokerPortAndHost.substring(0, pos);\n        } else {\n            throw new IllegalArgumentException(\"Illegal broker host:port '\" + brokerPortAndHost + \"'\");\n        }\n    }\n\n    private void writeHAProxyMessage() {\n        if (proxyConnection.hasHAProxyMessage()) {\n            final ByteBuf msg = encodeProxyProtocolMessage(proxyConnection.getHAProxyMessage());\n            writeAndFlush(msg);\n        } else {\n            if (inboundChannel.remoteAddress() instanceof InetSocketAddress\n                    && inboundChannel.localAddress() instanceof InetSocketAddress) {\n                InetSocketAddress clientAddress = (InetSocketAddress) inboundChannel.remoteAddress();\n                String sourceAddress = clientAddress.getAddress().getHostAddress();\n                int sourcePort = clientAddress.getPort();\n                InetSocketAddress proxyAddress = (InetSocketAddress) inboundChannel.localAddress();\n                String destinationAddress = proxyAddress.getAddress().getHostAddress();\n                int destinationPort = proxyAddress.getPort();\n                HAProxyMessage msg = new HAProxyMessage(HAProxyProtocolVersion.V1, HAProxyCommand.PROXY,\n                        HAProxyProxiedProtocol.TCP4, sourceAddress, destinationAddress, sourcePort,","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/DirectProxyHandler.java#L177-L213","documentation":"parseHost splits a 'host:port' broker string at the last colon; if there is no colon it cannot extract a host and throws IllegalArgumentException. It is called from DirectProxyHandler.connect when the proxy opens a direct connection to the target broker.","triggerScenarios":"connect(brokerPortAndHost, ...) receiving a string without a ':' separator — e.g. a bare hostname, an empty value, or a broker service URL missing its port component.","commonSituations":"Misconfigured brokerServiceURL without the port; a lookup result altered by a custom discovery layer; trimming the ':6650' when copying config between environments; IPv6 literal handled without brackets in surrounding code.","solutions":["Ensure the broker target string always includes a port, e.g. '10.0.0.1:6650'","Fix brokerServiceURL / discovery configuration so it returns full host:port values","Log the incoming brokerPortAndHost at the call site to find which component produced the malformed value","For IPv6 hosts, ensure bracketed literals like '[::1]:6650' so lastIndexOf(':') finds the port separator"],"exampleFix":"// before\nbrokerServiceURL=pulsar://broker-1\n// after\nbrokerServiceURL=pulsar://broker-1:6650","handlingStrategy":"validation","validationCode":"// Guard before passing a broker string to the direct proxy handler\nstatic boolean isHostPort(String s) {\n    return s != null && s.lastIndexOf(':') > 0 && s.lastIndexOf(':') < s.length() - 1;\n}","typeGuard":"boolean isHostPort(String s) {\n    int pos = s == null ? -1 : s.lastIndexOf(':');\n    return pos > 0 && pos < s.length() - 1;\n}","tryCatchPattern":"try { handler.connect(brokerPortAndHost, ...); } catch (IllegalArgumentException e) { log.error(\"Broker target must be host:port, got: {}\", brokerPortAndHost); throw e; }","preventionTips":["Always include the port in brokerServiceURL (pulsar://host:6650)","Use bracketed IPv6 literals like [::1]:6650","Assert host:port format wherever custom discovery produces broker targets"],"tags":["pulsar-proxy","configuration","url-parsing"],"backgroundTag":"illegal-host-port-format","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}