{"record":{"id":"b57158e59d7b6222","repo":"SonarSource/sonarqube","slug":"eskeystorecli-has-been-interrupted","errorCode":null,"errorMessage":"EsKeyStoreCli has been interrupted","messagePattern":"EsKeyStoreCli has been interrupted","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"server/sonar-main/src/main/java/org/sonar/application/es/EsKeyStoreCli.java","lineNumber":104,"sourceCode":"    try (OutputStream stdin = process.getOutputStream();\n      BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin, StandardCharsets.UTF_8))) {\n      for (Entry<String, String> entry : properties.entrySet()) {\n        writer.write(entry.getValue());\n        writer.write(\"\\n\");\n      }\n      writer.flush();\n\n    } catch (IOException e) {\n      throw new IllegalStateException(e);\n    }\n  }\n\n  private static void waitFor(Process process) {\n    try {\n      process.waitFor(1, TimeUnit.MINUTES);\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new IllegalStateException(\"EsKeyStoreCli has been interrupted\", e);\n    }\n  }\n\n  private static void checkExitValue(int code) {\n    if (code != 0) {\n      throw new IllegalStateException(\"Elasticsearch KeyStore tool exited with code: \" + code);\n    }\n  }\n\n  public static class EsKeyStoreJvmOptions extends JvmOptions<EsKeyStoreJvmOptions> {\n\n    public EsKeyStoreJvmOptions(EsInstallation esInstallation) {\n      super(mandatoryOptions(esInstallation));\n    }\n\n    private static Map<String, String> mandatoryOptions(EsInstallation esInstallation) {\n      Map<String, String> res = LinkedHashMap.newLinkedHashMap(7);\n      res.put(\"-Xms4m\", \"\");","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/es/EsKeyStoreCli.java#L86-L122","documentation":"EsKeyStoreCli.waitFor waits up to one minute for the external Elasticsearch KeyStore CLI process to finish. If the waiting thread is interrupted, it restores the interrupt flag and throws IllegalStateException 'EsKeyStoreCli has been interrupted'. It signals the keystore-setup step was cancelled mid-run (typically shutdown).","triggerScenarios":"The thread executing executeWith -> waitFor receives an interrupt while blocked in Process.waitFor(1, MINUTES) — normally during application shutdown.","commonSituations":"Server shutdown or kill while Elasticsearch keystore initialization is still running; supervision frameworks restarting the process; long-running keyStore CLI exceeding expectations combined with a shutdown request.","solutions":["Allow the keystore setup to complete before shutting down the server","Check what triggered the interrupt (shutdown hook, container SIGTERM) and delay stop until after ES init","Re-run startup to complete keystore initialization cleanly","If interrupts are frequent, increase startup orchestration timeouts"],"exampleFix":"// orchestration before\nkill -TERM $PID  # during keystore setup -> interrupted\n// after\n# wait for 'web process started' in logs (ES keystore done) before stopping/restarting","handlingStrategy":"try-catch","validationCode":"// ensure no shutdown is pending before starting ES keystore setup\nif (shutdownInProgress.get()) throw new IllegalStateException(\"Skip ES keystore setup: shutdown pending\");","typeGuard":null,"tryCatchPattern":"try { esKeyStoreCli.executeWith(...); } catch (IllegalStateException e) { if (e.getMessage().equals(\"EsKeyStoreCli has been interrupted\")) { log.warn(\"ES keystore setup interrupted; will retry on next start\"); return; } throw e; }","preventionTips":["Sequence shutdowns to avoid SIGTERM during ES initialization","Increase container stop grace periods above keystore setup duration","Monitor startup logs and stop only after the server reports ready","Treat interrupts during init as recoverable and retry on next start"],"tags":["process","interruption","elasticsearch","shutdown"],"backgroundTag":"request-timeout","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}