{"record":{"id":"3ea6f1afc7ebb3ed","repo":"SonarSource/sonarqube","slug":"can-not-resolve-host","errorCode":null,"errorMessage":"Can not resolve host [","messagePattern":"Can not resolve host \\[","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java","lineNumber":169,"sourceCode":"          .setTlsStrategy(\n            ClientTlsStrategyBuilder.create()\n              .setSslContext(getSSLContext(keyStorePath, keyStorePassword))\n              .build())\n          .build());\n    }\n    return builder.build();\n  }\n\n  private HttpHost toHttpHost(HostAndPort host) {\n    try {\n      String scheme = keyStorePath != null ? \"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 SSLContext getSSLContext(Path keyStorePath, @Nullable String keyStorePassword) {\n    try {\n      KeyStore keyStore = KeyStore.getInstance(\"pkcs12\");\n      try (InputStream is = Files.newInputStream(keyStorePath)) {\n        keyStore.load(is, keyStorePassword == null ? null : keyStorePassword.toCharArray());\n      }\n      SSLContextBuilder sslBuilder = SSLContexts.custom().loadTrustMaterial(keyStore, null);\n      return sslBuilder.build();\n    } catch (IOException | GeneralSecurityException e) {\n      throw new IllegalStateException(\"Failed to setup SSL context on ES client\", e);\n    }\n  }\n\n  /**\n   * Holds the ES client together with the underlying Rest5Client so we can close the latter on stop().","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/es/EsConnectorImpl.java#L151-L187","documentation":"EsConnectorImpl.toHttpHost resolves each Elasticsearch node hostname to an IP address via InetAddress.getByName. If DNS lookup fails (UnknownHostException), it wraps it into an IllegalStateException 'Can not resolve host [<host>]'. The ES client cannot be built without a resolvable node address.","triggerScenarios":"Building the ES connector when a configured search node host (e.g. from sonar.search.hosts / cluster config) cannot be resolved by DNS or /etc/hosts.","commonSituations":"Typos in the Elasticsearch host name; DNS outages; running in Docker/Kubernetes with a stale or missing service name; IPv6-only environments where 'java.net.preferIPv6Addresses' is set but resolution still fails.","solutions":["Fix the hostname in the search cluster configuration or /etc/hosts","Verify DNS resolution from the server: getent hosts <hostname> or nslookup","Check container/service names and namespace when running in Docker/Kubernetes","Retry after resolving network/DNS outages"],"exampleFix":"// before\nsonar.search.hosts=es-master.internal.example\n// after (fix DNS or use resolvable name/IP)\nsonar.search.hosts=es-master.svc.cluster.local","handlingStrategy":"try-catch","validationCode":"try { InetAddress.getByName(esHost); } catch (UnknownHostException e) { throw new IllegalStateException(\"ES host not resolvable before startup: \" + esHost, e); }","typeGuard":"static boolean resolvable(String host) { try { InetAddress.getByName(host); return true; } catch (UnknownHostException e) { return false; } }","tryCatchPattern":"try { esConnector.start(); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Can not resolve host\")) { waitForDnsOrFixConfig(); } throw e; }","preventionTips":["Validate ES hostnames with a DNS lookup in startup preflight checks","Use fully qualified names in container environments","Keep /etc/hosts and DNS consistent across cluster nodes","Add retry-with-backoff for transient DNS failures"],"tags":["network","dns","elasticsearch","sonarqube"],"backgroundTag":"connection-refused","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"}