SonarSource/sonarqube · error · IllegalStateException
Can not resolve host [
Error message
Can not resolve host [
What it means
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.
Source
Thrown at server/sonar-server-common/src/main/java/org/sonar/server/es/EsClientProvider.java:101
}
private static List<HttpHost> getHttpHosts(Configuration config) {
return Arrays.stream(config.getStringArray(CLUSTER_SEARCH_HOSTS.getKey()))
.map(HostAndPort::fromString)
.map(host -> toHttpHost(host, config))
.toList();
}
private static HttpHost toHttpHost(HostAndPort host, Configuration config) {
try {
String scheme = config.get(CLUSTER_ES_HTTP_KEYSTORE.getKey()).isPresent() ? "https" : "http";
InetAddress address = InetAddress.getByName(host.getHost());
if ("true".equalsIgnoreCase(System.getProperty("java.net.preferIPv6Addresses"))) {
return new HttpHost(scheme, address, host.getHost(), host.getPortOrDefault(9001));
}
return new HttpHost(scheme, address, host.getPortOrDefault(9001));
} catch (UnknownHostException e) {
throw new IllegalStateException("Can not resolve host [" + host + "]", e);
}
}
private static String displayedAddresses(List<HttpHost> httpHosts) {
return httpHosts.stream().map(HttpHost::toString).collect(Collectors.joining(", "));
}
}
View on GitHub (pinned to 184c821202)
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.
Example fix
// before (sonar.properties) sonar.search.hosts=elastic-1.internal // after (resolvable name or IP) sonar.search.hosts=elasticsearch.sonarqube.svc.cluster.local
Defensive patterns
Strategy: validation
Validate before calling
// before configuring the ES client
try { java.net.InetAddress.getByName(configuredHost); } catch (java.net.UnknownHostException e) { throw new IllegalStateException("Unresolvable ES host: " + configuredHost, e); } Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Can not resolve host [. Please check network settings and pr
- Address in property %s is not a valid address: %s
- Can not resolve host [
- Failed to validate configuration, check URL and Private Key
- Could not validate GitLab write permission. Got an unexpecte
AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09).
Data as JSON: /api/errors/973997b8ae8ec08d.
Report an issue: GitHub.