{"record":{"id":"35d1c52ae07b098a","repo":"apache/iceberg","slug":"error-generating-host-name","errorCode":null,"errorMessage":"Error generating host name","messagePattern":"Error generating host name","errorType":"exception","errorClass":"LockException","httpStatus":null,"severity":"error","filePath":"hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java","lineNumber":277,"sourceCode":"    }\n  }\n\n  /**\n   * Creates a lock, retrying if possible on failure.\n   *\n   * @return The {@link LockInfo} object for the successfully created lock\n   * @throws LockException When we are not able to fill the hostname for lock creation, or there is\n   *     an error during lock creation\n   */\n  @SuppressWarnings(\"ReverseDnsLookup\")\n  private LockInfo createLock() throws LockException {\n    LockInfo lockInfo = new LockInfo();\n\n    String hostName;\n    try {\n      hostName = InetAddress.getLocalHost().getHostName();\n    } catch (UnknownHostException uhe) {\n      throw new LockException(uhe, \"Error generating host name\");\n    }\n\n    LockComponent lockComponent =\n        new LockComponent(LockType.EXCLUSIVE, LockLevel.TABLE, databaseName);\n    lockComponent.setTablename(tableName);\n    LockRequest lockRequest =\n        new LockRequest(Lists.newArrayList(lockComponent), HiveHadoopUtil.currentUser(), hostName);\n\n    // Only works in Hive 2 or later.\n    if (HiveVersion.min(HiveVersion.HIVE_2)) {\n      lockRequest.setAgentInfo(agentInfo);\n    }\n\n    AtomicBoolean interrupted = new AtomicBoolean(false);\n    Tasks.foreach(lockRequest)\n        .retry(Integer.MAX_VALUE - 100)\n        .exponentialBackoff(\n            lockCreationMinWaitTime, lockCreationMaxWaitTime, lockCreationTimeout, 2.0)","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreLock.java#L259-L295","documentation":"Before requesting a metastore lock, MetastoreLock resolves the local hostname to populate the lock's agentInfo so it can later identify its own lock. If InetAddress.getLocalHost() throws UnknownHostException, the JVM cannot resolve the machine's own hostname and a LockException is thrown. This is an environment/DNS configuration problem, not a table-state problem.","triggerScenarios":"Any Hive-catalog table commit on a host whose hostname cannot be resolved: /etc/hosts missing the hostname entry, DNS misconfiguration, or containers with unresolvable hostnames.","commonSituations":"Kubernetes pods or Docker containers with random hostnames not registered in DNS; bare-metal clusters where /etc/hosts lacks the node's own hostname; IPv6-only or chrooted environments with broken resolver config.","solutions":["Add the machine's hostname to /etc/hosts (e.g. '127.0.0.1 myhost') so InetAddress.getLocalHost() resolves.","Fix resolver configuration (/etc/resolv.conf, /etc/nsswitch.conf) so the hostname resolves via DNS.","In containers, set HOSTNAME and ensure the pod's hostname is resolvable, or use a hostNetwork/DNS policy that registers it.","Verify with 'hostname -i' or a tiny JVM test calling InetAddress.getLocalHost() before deploying."],"exampleFix":"// before (shell on the failing node)\n$ hostname  # mypod-7f9c, not resolvable\n// after\n$ echo \"127.0.0.1 mypod-7f9c\" >> /etc/hosts  # or fix cluster DNS","handlingStrategy":"validation","validationCode":"import java.net.InetAddress;\nboolean hostnameResolvable() {\n  try { return !InetAddress.getLocalHost().getHostName().isEmpty(); }\n  catch (UnknownHostException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  table.commit(apply);\n} catch (LockException e) {\n  if (e.getMessage().contains(\"Error generating host name\")) {\n    throw new IllegalStateException(\"Fix /etc/hosts or DNS so the node hostname resolves\", e);\n  }\n  throw e;\n}","preventionTips":["Add hostname -> 127.0.0.1 mapping in /etc/hosts on every worker node","Validate hostname resolution in node startup health checks before running jobs","In containers, set resolvable HOSTNAME or fix cluster DNS policy","Test InetAddress.getLocalHost() in your deployment smoke tests"],"tags":["network","dns","hostname","hive"],"backgroundTag":"hostname-resolution-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}