{"record":{"id":"973997b8ae8ec08d","repo":"SonarSource/sonarqube","slug":"can-not-resolve-host-973997","errorCode":null,"errorMessage":"Can not resolve host [","messagePattern":"Can not resolve host \\[","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java","lineNumber":101,"sourceCode":"  }\n\n  private static List<HttpHost> getHttpHosts(Configuration config) {\n    return Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS.getKey()))\n      .map(HostAndPort::fromString)\n      .map(host -> toHttpHost(host, config))\n      .toList();\n  }\n\n  private static HttpHost toHttpHost(HostAndPort host, Configuration config) {\n    try {\n      String scheme = config.get(CLUSTER_ES_HTTP_KEYSTORE.getKey()).isPresent() ? \"https\" : \"http\";\n      InetAddress address = InetAddress.getByName(host.getHost());\n      if (\"true\".equalsIgnoreCase(System.getProperty(\"java.net.preferIPv6Addresses\"))) {\n        return new HttpHost(scheme, address, host.getHost(), host.getPortOrDefault(9001));\n      }\n      return new HttpHost(scheme, address, host.getPortOrDefault(9001));\n    } catch (UnknownHostException e) {\n      throw new IllegalStateException(\"Can not resolve host [\" + host + \"]\", e);\n    }\n  }\n\n  private static String displayedAddresses(List<HttpHost> httpHosts) {\n    return httpHosts.stream().map(HttpHost::toString).collect(Collectors.joining(\", \"));\n  }\n}\n","sourceCodeStart":83,"sourceCodeEnd":109,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java#L83-L109","documentation":"EsClientProvider.toHttpHost resolves each configured Elasticsearch hostname to an IP address via InetAddress.getByName. When DNS resolution fails it wraps the UnknownHostException in an IllegalStateException naming the host entry. This fails fast at client construction rather than producing a partially configured ES client.","triggerScenarios":"Elasticsearch client provisioning when a configured sonar.search.hosts entry (from the SONARQUBE_WEB_JSON properties) cannot be resolved by DNS, e.g. host misspelled, DNS down, or container name not resolvable.","commonSituations":"Docker/Kubernetes where the 'sonar-search' hostname is wrong; /etc/hosts or DNS misconfiguration; ES server not started yet in dev; typo in SONAR_ES_HOST or sonar.search.hosts; IPv6-only environments.","solutions":["Fix the configured hostname in sonar.search.hosts so it resolves (test with `nslookup <host>` or `getent hosts <host>`).","Verify DNS/network connectivity from the SonarQube host; check /etc/resolv.conf, /etc/hosts, or cluster DNS.","If ES is in a container, ensure the alias/service name matches the configured host and the container is running.","Restart SonarQube after correcting the setting; the error is fatal at startup."],"exampleFix":"// before (sonar.properties)\nsonar.search.hosts=elastic-1.internal\n// after (resolvable name or IP)\nsonar.search.hosts=elasticsearch.sonarqube.svc.cluster.local","handlingStrategy":"validation","validationCode":"// before configuring the ES client\ntry { java.net.InetAddress.getByName(configuredHost); } catch (java.net.UnknownHostException e) { throw new IllegalStateException(\"Unresolvable ES host: \" + configuredHost, e); }","typeGuard":null,"tryCatchPattern":"try { startEsClient(); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Can not resolve host\")) { log.error(\"Fix sonar.search.hosts: {}\", e.getMessage(), e.getCause()); } throw e; }","preventionTips":["Validate every host with DNS lookup at config load time","Use fully qualified domain names or stable IPs","Prefer service discovery names that exist before SonarQube starts","Monitor DNS health in containerized deployments"],"tags":["dns","elasticsearch","network","configuration"],"backgroundTag":"dns-resolution-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}