prestodb/presto · error · ClientException
Fully qualified name of localhost should not resolve to 'loc
Error message
Fully qualified name of localhost should not resolve to 'localhost'. System configuration error?
What it means
canonicalizeServiceHostName resolves the host to a fully qualified name via InetAddress canonical host names, and refuses 'localhost' as the result, throwing a ClientException. SPNEGO service principals must contain the real FQDN (HTTP/host.example.com@REALM); a localhost resolution means the machine's hostname/network is misconfigured and the resulting principal would not match the KDC.
Source
Thrown at presto-client/src/main/java/com/facebook/presto/client/SpnegoHandler.java:261
if (useCanonicalHostname) {
serviceHostName = canonicalizeServiceHostName(hostName);
}
return format("%s@%s", serviceName, serviceHostName.toLowerCase(Locale.US));
}
private static String canonicalizeServiceHostName(String hostName)
{
try {
InetAddress address = InetAddress.getByName(hostName);
String fullHostName;
if ("localhost".equalsIgnoreCase(address.getHostName())) {
fullHostName = InetAddress.getLocalHost().getCanonicalHostName();
}
else {
fullHostName = address.getCanonicalHostName();
}
if (fullHostName.equalsIgnoreCase("localhost")) {
throw new ClientException("Fully qualified name of localhost should not resolve to 'localhost'. System configuration error?");
}
return fullHostName;
}
catch (UnknownHostException e) {
throw new ClientException("Failed to resolve host: " + hostName, e);
}
}
private interface GssSupplier<T>
{
T get()
throws GSSException;
}
private static <T> T doAs(Subject subject, GssSupplier<T> action)
throws GSSException
{
try {View on GitHub (pinned to 55bb57d202)
Solutions
- Fix /etc/hosts so the machine's real hostname maps to its real IP, with 127.0.0.1 pointing only to 'localhost'.
- Set a proper hostname (hostnamectl set-hostname host.example.com).
- Fix reverse DNS (PTR record) with your DNS admin so the IP canonicalizes to the FQDN.
- Verify with: hostname -f (must not print 'localhost').
Example fix
// before (in /etc/hosts) 127.0.0.1 myhost.example.com myhost localhost // after 127.0.0.1 localhost 10.0.0.5 myhost.example.com myhost
Defensive patterns
Strategy: validation
Validate before calling
String fqdn = InetAddress.getLocalHost().getCanonicalHostName();
if ("localhost".equalsIgnoreCase(fqdn)) {
throw new IllegalStateException("Fix /etc/hosts or hostname: FQDN resolves to localhost");
} Try / catch
try { ... } catch (ClientException e) { if (e.getMessage().contains("should not resolve to 'localhost'")) { /* fix hostname/DNS config */ } throw e; } Prevention
- Ensure hostname -f does not return 'localhost'
- Keep 127.0.0.1 mapped only to localhost in /etc/hosts
- Configure proper reverse DNS (PTR records)
- Set real hostnames in container images
When it happens
Trigger: makeServicePrincipal -> canonicalizeServiceHostName when InetAddress.getLocalHost().getCanonicalHostName() (or the given address's) resolves to the string 'localhost'.
Common situations: /etc/hosts maps the machine's hostname to 127.0.0.1 or lists 'localhost' as canonical name; hostname set to 'localhost'; reverse DNS returning 'localhost'; container images with incomplete hostname setup.
Related errors
- Kerberos error for [%s]: %s
- Failed to resolve host:
- Authentication using Kerberos requires SSL to be enabled
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/5993ddecd8989776.
Report an issue: GitHub.