{"record":{"id":"080011665057d26f","repo":"elastic/elasticsearch","slug":"failed-to-write-unicast-hosts-for","errorCode":null,"errorMessage":"Failed to write unicast_hosts for {}","messagePattern":"Failed to write unicast_hosts for (.+?)","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":null,"severity":"error","filePath":"build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java","lineNumber":551,"sourceCode":"    }\n\n    @Override\n    public void requiresFeature(String feature, Version from) {\n        nodes.all(node -> node.requiresFeature(feature, from));\n    }\n\n    @Override\n    public void requiresFeature(String feature, Version from, Version until) {\n        nodes.all(node -> node.requiresFeature(feature, from, until));\n    }\n\n    public void writeUnicastHostsFiles() {\n        String unicastUris = nodes.stream().flatMap(node -> node.getAllTransportPortURI().stream()).collect(Collectors.joining(\"\\n\"));\n        nodes.forEach(node -> {\n            try {\n                Files.writeString(node.getConfigDir().resolve(\"unicast_hosts.txt\"), unicastUris);\n            } catch (IOException e) {\n                throw new UncheckedIOException(\"Failed to write unicast_hosts for \" + this, e);\n            }\n        });\n    }\n\n    @Override\n    @Internal\n    public String getHttpSocketURI() {\n        waitForAllConditions();\n        return getFirstNode().getHttpSocketURI();\n    }\n\n    @Override\n    @Internal\n    public String getTransportPortURI() {\n        waitForAllConditions();\n        return getFirstNode().getTransportPortURI();\n    }\n","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java#L533-L569","documentation":"Thrown by ElasticsearchCluster.writeUnicastHostsFiles when Files.writeString fails on any node's configDir/unicast_hosts.txt. unicast_hosts.txt is the discovery seed file the nodes use to find each other; failing to write it breaks cluster formation.","triggerScenarios":"An IOException while writing the unicast host list for one of the cluster's nodes — disk full, permission denied, parent dir missing, or the node's configDir being invalid.","commonSituations":"Insufficient disk space in the test working directory; the node's home/config dir was deleted out from under the writer; permission issues in a containerized CI environment; path length limits on Windows.","solutions":["Check disk space and write permissions on the test cluster's working directory (often under build/testclusters/).","Ensure no concurrent process is removing node config dirs while the cluster is being configured.","Clean stale cluster dirs: rm -rf build/testclusters and rerun.","On Windows, verify path lengths stay within OS limits for the cluster home."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"Path dir = node.getConfigDir();\nif (!Files.isWritable(dir)) {\n    throw new IllegalStateException(\"Config dir not writable: \" + dir);\n}\n// also check disk: Files.getFileStore(dir).getUsableSpace()","typeGuard":null,"tryCatchPattern":"try {\n    cluster.writeUnicastHostsFiles();\n} catch (UncheckedIOException e) {\n    log.error(\"Failed writing unicast_hosts for {}, cause={}\", cluster, e.getCause());\n    throw e; // or fall back to retry after ensuring parent dirs exist\n}","preventionTips":["Ensure build/testclusters is on a writable disk with adequate free space.","Avoid concurrent clean tasks that may remove node dirs mid-config.","On Windows, keep cluster home paths short to avoid MAX_PATH limits."],"tags":["test","testclusters","io","discovery","filesystem"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}