{"record":{"id":"5ad15a74cc476441","repo":"elastic/elasticsearch","slug":"elasticsearch-died-while-starting-up-exit-code","errorCode":null,"errorMessage":"Elasticsearch died while starting up, exit code: ${exitCode}","messagePattern":"Elasticsearch died while starting up, exit code: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/WindowsServiceDaemon.java","lineNumber":106,"sourceCode":"        pb.environment().clear();\n        pb.environment().putAll(environment);\n        pb.directory(new File(workingDir.toString()));\n        pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);\n\n        Process jvmProcess = null;\n        ErrorPumpThread errorPump;\n        boolean success = false;\n\n        try {\n            jvmProcess = pb.start();\n            errorPump = new ErrorPumpThread(jvmProcess.getErrorStream(), System.err);\n            errorPump.start();\n            sendServerArgs(serverArgsBytes, jvmProcess.getOutputStream());\n\n            boolean serverOk = errorPump.waitUntilReady();\n            if (serverOk == false) {\n                int exitCode = jvmProcess.waitFor();\n                throw new RuntimeException(\"Elasticsearch died while starting up, exit code: \" + exitCode);\n            }\n            success = true;\n        } catch (InterruptedException e) {\n            throw new RuntimeException(e);\n        } catch (IOException e) {\n            throw new UncheckedIOException(e);\n        } finally {\n            if (success == false && jvmProcess != null && jvmProcess.isAlive()) {\n                jvmProcess.destroyForcibly();\n            }\n        }\n\n        return new ServerProcess(jvmProcess, errorPump);\n    }\n\n    private static String getJavaCommand(ProcessInfo processInfo) {\n        Path javaHome = Path.of(processInfo.sysprops().get(\"java.home\"));\n        return javaHome.resolve(\"bin\").resolve(\"java.exe\").toString();","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/distribution/tools/windows-service-cli/src/main/java/org/elasticsearch/windows/service/WindowsServiceDaemon.java#L88-L124","documentation":"Thrown by WindowsServiceDaemon when the spawned Elasticsearch JVM process exits before the ErrorPumpThread signals that the server is ready. The error includes the JVM's exit code, which is the single most useful diagnostic. This is a wrapper around a process-level death: the JVM started, ran briefly, and returned non-zero, so the cause is almost always visible earlier in the ErrorPump output or in the Elasticsearch log file.","triggerScenarios":"JVM exits due to fatal startup error: invalid jvm.options, OOM during bootstrap, missing required setting, entitlement violation, port already in use, or classpath corruption. The ErrorPump's `waitUntilReady` returns false because it never observed the readiness marker.","commonSituations":"First run after an upgrade with incompatible jvm.options. Locked memory (bootstrap checks) failing on a non-systemd Windows host. bind() collision on http/transport ports. Insufficient heap.","solutions":["Read the ErrorPump output printed just before this exception — it usually contains the real cause.","Open the Elasticsearch log file under logs/ for the full stack trace.","Cross-reference the exit code: 1 = generic JVM error, 137 = OOM-kill, 134 = JVM crash (hs_err_pid file).","Validate jvm.options and elasticsearch.yml with a config-only boot (`-E` dry run) before starting as a service.","For hs_err crashes, inspect the hs_err_pid*.log file in the working directory."],"exampleFix":"REM before: service starts, JVM dies with exit code 1\nREM inspect logs:\ntype %ES_HOME%\\logs\\elasticsearch.log\nREM after: fix the offending setting (e.g. remove unsupported -XX flag)\nbin\\elasticsearch-service.bat start","handlingStrategy":"try-catch","validationCode":"// Before running as a service, validate config with a foreground run:\n// bin/elasticsearch -E ...  (exits non-zero if config is bad)\n// Capture exit code; only register as a service if foreground run succeeds.","typeGuard":"static boolean jvmLooksHealthy(Path logsDir) throws IOException {\n    // Returns true if the latest log line indicates successful startup markers\n    return Files.lines(logsDir.resolve(\"elasticsearch.log\"))\n        .anyMatch(l -> l.contains(\"started\") || l.contains(\"bound_addresses\"));\n}","tryCatchPattern":"try {\n    WindowsServiceDaemon.main(args);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"died while starting up\")) {\n        // read logs/elasticsearch.log and the ErrorPump output to find root cause\n        log.error(\"Elasticsearch failed to start as a service; inspect logs/\", e);\n    } else throw e;\n}","preventionTips":["Always validate config with a foreground run before installing as a service.","Capture stdout/stderr of the JVM in the service log directory.","Watch for hs_err_pid*.log files indicating JVM crashes."],"tags":["windows","service","jvm","startup","diagnostics","process"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}