{"record":{"id":"59e41778ea664b66","repo":"walkor/workerman","slug":"bad-remoteaddress","errorCode":null,"errorMessage":"Bad remoteAddress","messagePattern":"Bad remoteAddress","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Connection/AsyncTcpConnection.php","lineNumber":188,"sourceCode":"     */\n    protected int $reconnectTimer = 0;\n\n    /**\n     * Construct.\n     *\n     * @param string $remoteAddress\n     * @param array $socketContext\n     */\n    public function __construct(string $remoteAddress, array $socketContext = [])\n    {\n        $addressInfo = parse_url($remoteAddress);\n        if (!$addressInfo) {\n            [$scheme, $this->remoteAddress] = explode(':', $remoteAddress, 2);\n            if ('unix' === strtolower($scheme)) {\n                $this->remoteAddress = substr($remoteAddress, strpos($remoteAddress, '/') + 2);\n            }\n            if (!$this->remoteAddress) {\n                throw new RuntimeException('Bad remoteAddress');\n            }\n        } else {\n            $addressInfo['port'] ??= 0;\n            $addressInfo['path'] ??= '/';\n            if (!isset($addressInfo['query'])) {\n                $addressInfo['query'] = '';\n            } else {\n                $addressInfo['query'] = '?' . $addressInfo['query'];\n            }\n            $this->remoteHost = $addressInfo['host'];\n            $this->remotePort = $addressInfo['port'];\n            $this->remoteURI = \"{$addressInfo['path']}{$addressInfo['query']}\";\n            $scheme = $addressInfo['scheme'] ?? 'tcp';\n            $this->remoteAddress = 'unix' === strtolower($scheme)\n                ? substr($remoteAddress, strpos($remoteAddress, '/') + 2)\n                : $this->remoteHost . ':' . $this->remotePort;\n        }\n","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/walkor/workerman/blob/1391112a61d23020e11e7b89f17050f6cfaea431/src/Connection/AsyncTcpConnection.php#L170-L206","documentation":"Thrown by the AsyncTcpConnection constructor when the $remoteAddress string is too malformed to use. The constructor first tries parse_url(); when that fails it falls back to splitting the string on the first ':' and requires a non-empty remainder (host:port, or a path for unix://). If nothing usable remains after the scheme, Workerman cannot build a connection target and aborts.","triggerScenarios":"Calling new AsyncTcpConnection() with an address that has no host part: 'tcp:', 'text://', 'unix://', 'ssl://', or an empty string. Also any address where parse_url() returns false and the part after the first ':' is empty or only slashes.","commonSituations":"The address is assembled from config or environment variables and the host variable is empty at runtime; passing a placeholder like 'ws://' with the host meant to be filled in later; a typo such as 'tcp//host:80'; address truncated by string concatenation bugs.","solutions":["Pass a complete address with scheme, host and port, e.g. 'tcp://127.0.0.1:8080', 'ws://site.com:443', or a full path for unix sockets like 'unix:///tmp/app.sock'","Check that the host/port variables used to build the address are non-empty before constructing the connection","Validate the address with parse_url() in your own config-loading code so bad values fail loudly at startup, not at connect time"],"exampleFix":"// before\n$host = $config['host'] ?? ''; // empty due to missing config key\n$conn = new AsyncTcpConnection(\"tcp://$host:8080\"); // throws 'Bad remoteAddress'\n\n// after\n$host = $config['host'] ?? '';\nif ($host === '') {\n    throw new InvalidArgumentException('config[host] is empty');\n}\n$conn = new AsyncTcpConnection(\"tcp://{$host}:8080\");","handlingStrategy":"validation","validationCode":"$address = \"tcp://{$host}:{$port}\";\n$info = parse_url($address);\n$ok = $info !== false\n    && (isset($info['host']) && $info['host'] !== '' || strtolower($info['scheme'] ?? '') === 'unix')\n    && ($info['scheme'] ?? '') !== '';\nif (!$ok || $host === '') {\n    throw new InvalidArgumentException(\"Invalid remote address: $address\");\n}\n$conn = new AsyncTcpConnection($address);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never build connection addresses by naive string concatenation with config values; assert each piece is non-empty first","Load and validate listen/connect addresses once at startup and fail fast with a clear config error","For unix sockets always pass the full absolute path: unix:///var/run/app.sock"],"tags":["php","workerman","async-tcp-connection","address-validation"],"backgroundTag":"invalid-endpoint-address","analyzedSha":"1391112a61d23020e11e7b89f17050f6cfaea431","analyzedAt":"2026-08-21T02:05:46.744Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}