{"record":{"id":"412a858ebbed82c6","repo":"oraios/serena","slug":"could-not-connect-to-self-connection-info-host","errorCode":null,"errorMessage":"Could not connect to {self._connection_info.host}:{self._connection_info.port} within {self._connection_info.connection_timeout}s","messagePattern":"Could not connect to (.+?):(.+?) within (.+?)s","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/solidlsp/ls_process.py","lineNumber":721,"sourceCode":"    def is_running(self) -> bool:\n        return self._sock is not None\n\n    def _start(self) -> None:\n        deadline = time.monotonic() + self._connection_info.connection_timeout\n        last_exc: Exception | None = None\n        while True:\n            try:\n                sock = socket.create_connection((self._connection_info.host, self._connection_info.port), timeout=5.0)\n                sock.settimeout(None)\n                self._sock = sock\n                self._file = sock.makefile(\"rb\")\n                log.info(\"TCPLanguageServer connected to %s:%d\", self._connection_info.host, self._connection_info.port)\n                break\n            except OSError as exc:\n                last_exc = exc\n                remaining = deadline - time.monotonic()\n                if remaining <= 0:\n                    raise RuntimeError(\n                        f\"Could not connect to {self._connection_info.host}:{self._connection_info.port} \"\n                        f\"within {self._connection_info.connection_timeout}s\"\n                    ) from last_exc\n                log.debug(\n                    \"TCPLanguageServer: connection failed (%s), retrying in %.1fs (%.0fs left)\",\n                    exc,\n                    self._connection_info.retry_interval,\n                    remaining,\n                )\n                time.sleep(min(self._connection_info.retry_interval, remaining))\n\n        threading.Thread(\n            target=self._read_loop,\n            name=f\"LSP-tcp-reader:{self.ls_id.value}\",\n            daemon=True,\n        ).start()\n\n    def _stop(self, timeout: float) -> None:","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/oraios/serena/blob/7fcbca7e62555ec2287ddb2f083caee805848ea6/src/solidlsp/ls_process.py#L703-L739","documentation":"RuntimeError raised in _start of TCPLanguageServer (src/solidlsp/ls_process.py:721) when a TCP connection to the language server could not be established within connection_timeout seconds. The last OSError from the socket attempts is attached via `from`.","triggerScenarios":"Launching a TCP-based language server that fails to bind/listen on the configured host:port, binds on a different interface than expected, or takes longer than connection_timeout to become ready.","commonSituations":"Firewall or container networking blocking localhost ports; server configured to listen on a different port/host; slow startup on loaded machines exceeding the timeout; host mismatch (127.0.0.1 vs 0.0.0.0 in containers).","solutions":["Increase connection_timeout in the connection info to accommodate slow server startup.","Verify the server process actually started (check for a sibling process-terminated error) and is listening on the configured host/port.","Check firewall/security software and container network settings blocking the port.","Confirm host/port values match the server's own listen configuration."],"exampleFix":"// before\nConnectionInfo(host=\"127.0.0.1\", port=9999, connection_timeout=1.0)\n// after\nConnectionInfo(host=\"127.0.0.1\", port=9999, connection_timeout=30.0)","handlingStrategy":"validation","validationCode":"import socket\ns = socket.socket()\ns.settimeout(2)\ntry:\n    s.connect((host, port))\n    s.close()\nexcept OSError as e:\n    raise ConfigError(f\"port {port} unreachable: {e}\")","typeGuard":"def conn_info_ok(info: ConnectionInfo) -> bool:\n    return info.connection_timeout >= 10 and info.port > 0","tryCatchPattern":"try:\n    ls = TcpLanguageServer(conn_info)\nexcept RuntimeError as e:\n    if \"Could not connect\" in str(e):\n        conn_info.connection_timeout *= 4\n        ls = TcpLanguageServer(conn_info)\n    else:\n        raise","preventionTips":["Set generous connection_timeout on slow or loaded machines","Verify host/port match the server's listen configuration","Check firewall/container networking before deployment","Confirm the server process stays alive while connecting"],"tags":["network","tcp","timeout"],"backgroundTag":"connection-timeout","analyzedSha":"7fcbca7e62555ec2287ddb2f083caee805848ea6","analyzedAt":"2026-08-29T00:04:09.619Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}