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

  1. Fix the configured hostname in sonar.search.hosts so it resolves (test with `nslookup <host>` or `getent hosts <host>`).
  2. Verify DNS/network connectivity from the SonarQube host; check /etc/resolv.conf, /etc/hosts, or cluster DNS.
  3. If ES is in a container, ensure the alias/service name matches the configured host and the container is running.
  4. 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

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


AI-assisted analysis of SonarSource/sonarqube@184c821202 (2026-09-09). Data as JSON: /api/errors/973997b8ae8ec08d. Report an issue: GitHub.