{"record":{"id":"8445da68539c0d23","repo":"theonedev/onedev","slug":"unable-to-discover-cluster-ip-from-database-connec","errorCode":null,"errorMessage":"Unable to discover cluster ip from database connection url: ","messagePattern":"Unable to discover cluster ip from database connection url: ","errorType":"console","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"server-core/src/main/java/io/onedev/server/ServerConfig.java","lineNumber":146,"sourceCode":"\t\t\t\t\t\t\tdbPorts.put(StringUtils.substringBefore(part, \":\"), \n\t\t\t\t\t\t\t\t\tparseInt(StringUtils.substringAfter(part, \":\")));\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdbPorts.put(part, 5432);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tfor (var entry: dbPorts.entrySet()) {\n\t\t\t\t\ttry (Socket socket = new Socket()) {\n\t\t\t\t\t\tsocket.connect(new InetSocketAddress(entry.getKey(), entry.getValue()));\n\t\t\t\t\t\tclusterIp = socket.getLocalAddress().getHostAddress();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t} catch (Exception e) {\n\t\t\t\t\t\tlogger.warn(String.format(\"Connection failed (host: %s, port: %d)\", entry.getKey(), entry.getValue()), e);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (StringUtils.isBlank(clusterIp)) \n\t\t\t\t\tthrow new RuntimeException(\"Unable to discover cluster ip from database connection url: \" + dbUrl);\n\t\t\t}\n\t\t}\n\t\tthis.clusterIp = clusterIp;\n\n\t\tString clusterPortStr = System.getenv(PROP_CLUSTER_PORT);\n\t\tif (StringUtils.isBlank(clusterPortStr))\n\t\t\tclusterPortStr = props.getProperty(PROP_CLUSTER_PORT);\n\t\tif (StringUtils.isBlank(clusterPortStr))\n\t\t\tclusterPort = 5710;\n\t\telse\n\t\t\tclusterPort = parseInt(clusterPortStr.trim());\n\t}\n\n\tpublic int getHttpPort() {\n\t\treturn httpPort;\n\t}\n\n\tpublic int getSshPort() {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ServerConfig.java#L128-L164","documentation":"When clustering is enabled, ServerConfig must determine the server's cluster IP. If no cluster ip is configured explicitly, it tries to derive one from the hosts referenced by the database connection URL; if none of those hosts is reachable/matches, it throws this RuntimeException.","triggerScenarios":"Starting OneDev with clustering enabled (cluster port/prop set) without PROP_CLUSTER_IP set, and the JDBC URL hosts cannot be contacted or none of them yields an address, so clusterIp remains blank after the host probing loop.","commonSituations":"Kubernetes/container deployments where the DB hostname is not resolvable from the node, a firewall blocking the attempted connections, a jdbc url format the discovery logic cannot parse, or forgetting to set CLUSTER_IP env var.","solutions":["Set the cluster ip explicitly via the CLUSTER_IP environment variable (PROP_CLUSTER_IP) so discovery from the db url is unnecessary.","Verify network reachability to every host in the jdbc url from this server (telnet/nc the db host:port).","Check that the jdbc url is in an expected format containing resolvable host(s); fix malformed urls.","If clustering is not intended, remove cluster-related env/properties so the discovery path is not taken."],"exampleFix":"// before\ndocker run onedev  # no CLUSTER_IP set\n// after\ndocker run -e CLUSTER_IP=10.0.0.5 onedev","handlingStrategy":"validation","validationCode":"if (System.getenv(\"CLUSTER_PORT\") != null && System.getenv(\"CLUSTER_IP\") == null) {\n    // ensure explicit cluster ip is provided to skip db-url discovery\n    throw new IllegalStateException(\"Set CLUSTER_IP when clustering is enabled\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    new ServerConfig(...);\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Unable to discover cluster ip\")) {\n        // fall back: set CLUSTER_IP env var and restart\n    }\n}","preventionTips":["Always set CLUSTER_IP explicitly in cluster/container deployments.","Pre-verify db host reachability (DNS, firewall) before startup.","Keep jdbc urls in the documented format."],"tags":["cluster","network","startup","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}