elastic/elasticsearch · error · UncheckedIOException

Failed to run {} for {}

Error message

Failed to run {} for {}

What it means

Thrown by runElasticsearchBinScriptWithInput when LoggedExec.exec raises an IOException (the bin script was found, but the process could not be launched or the stream copy failed). The IOException is wrapped as UncheckedIOException with the tool name and node identity. This is a process-launch failure, not a non-zero exit code (LoggedExec handles exit codes separately).

Source

Thrown at build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java:795

            );
        }
        try (InputStream byteArrayInputStream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8))) {
            LoggedExec.exec(execOperations, spec -> {
                spec.setEnvironment(getESEnvironment());
                spec.workingDir(getDistroDir());
                spec.executable(OS.conditionalString().onUnix(() -> "./bin/" + tool).onWindows(() -> "cmd").supply());
                spec.args(OS.<List<CharSequence>>conditional().onWindows(() -> {
                    ArrayList<CharSequence> result = new ArrayList<>();
                    result.add("/c");
                    result.add("bin\\" + tool + ".bat");
                    Collections.addAll(result, args);
                    return result;
                }).onUnix(() -> Arrays.asList(args)).supply());
                spec.setStandardInput(byteArrayInputStream);

            });
        } catch (IOException e) {
            throw new UncheckedIOException("Failed to run " + tool + " for " + this, e);
        }
    }

    private void runKeystoreCommandWithPassword(String keystorePassword, String input, CharSequence... args) {
        final String actualInput = keystorePassword.length() > 0 ? keystorePassword + "\n" + input : input;
        runElasticsearchBinScriptWithInput(actualInput, "elasticsearch-keystore", args);
    }

    private void runElasticsearchBinScript(String tool, CharSequence... args) {
        runElasticsearchBinScriptWithInput("", tool, args);
    }

    private Map<String, String> getESEnvironment() {
        Map<String, String> defaultEnv = new HashMap<>();
        // If we are testing the current version of Elasticsearch, use the configured runtime Java, otherwise use the bundled JDK
        if (getTestDistribution() == TestDistribution.INTEG_TEST || getVersion().equals(VersionProperties.getElasticsearchVersion())) {
            defaultEnv.put("ES_JAVA_HOME", runtimeJava.get().getAbsolutePath());
        }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Inspect the wrapped IOException cause for the precise spawn error.
  2. On CI, raise ulimit -u / -n if process or fd limits are hit.
  3. Verify bin/<tool> is executable on disk (chmod +x); clean and re-extract the distro if not.
  4. Re-run; if transient, isolate which tool/path fails and capture stderr via esOutputFile.
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm the tool path is executable before relying on it
Path tool = node.getDistroDir().resolve("bin").resolve(toolName);
if (Files.exists(tool) && !Files.isExecutable(tool)) {
    throw new IllegalStateException("bin script not executable: " + tool);
}

Try / catch

try {
    node.start();
} catch (UncheckedIOException e) {
    if (e.getMessage().startsWith("Failed to run ")) {
        // process spawn failure; check ulimits, perms, AV
        throw new IllegalStateException("Bin script spawn failed: " + e.getCause(), e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Process spawn fails: the executable path is unreadable (permissions), the input ByteArrayInputStream cannot be read, execOperations cannot fork (process limit), or the OS refused the spawn. Also when the stdio redirection setup raises IOException inside the exec spec.

Common situations: Permissions on bin/elasticsearch-keystore not executable. Too many open files / process limit on a CI agent. Transient OS error spawning the process. Broken pipe to a closed parent. Disk/FS error reading the distro bin script.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/9e4aa51e91c8d216. Report an issue: GitHub.