{"record":{"id":"068f5f0e9f3dd5eb","repo":"SonarSource/sonarqube","slug":"could-not-delete-elasticsearch-temporary-conf-dire","errorCode":null,"errorMessage":"Could not delete Elasticsearch temporary conf directory","messagePattern":"Could not delete Elasticsearch temporary conf directory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java","lineNumber":158,"sourceCode":"  private void writeConfFiles(EsInstallation esInstallation) {\n    File confDir = esInstallation.getConfDirectory();\n\n    pruneElasticsearchConfDirectory(confDir);\n    createElasticsearchConfDirectory(confDir);\n    setupElasticsearchSecurity(esInstallation);\n\n    esInstallation.getEsYmlSettings().writeToYmlSettingsFile(esInstallation.getElasticsearchYml());\n    esInstallation.getEsJvmOptions().writeToJvmOptionFile(esInstallation.getJvmOptions());\n    storeElasticsearchLog4j2Properties(esInstallation);\n  }\n\n  private static void pruneElasticsearchConfDirectory(File confDir) {\n    try {\n      if (confDir.exists()) {\n        FileUtils2.deleteDirectory(confDir);\n      }\n    } catch (IOException e) {\n      throw new IllegalStateException(\"Could not delete Elasticsearch temporary conf directory\", e);\n    }\n  }\n\n  private static void createElasticsearchConfDirectory(File confDir) {\n    if (!confDir.mkdirs()) {\n      String error = format(\"Failed to create temporary configuration directory [%s]\", confDir.getAbsolutePath());\n      LOG.error(error);\n      throw new IllegalStateException(error);\n    }\n  }\n\n  private void setupElasticsearchSecurity(EsInstallation esInstallation) {\n    if (esInstallation.isSecurityEnabled()) {\n      EsKeyStoreCli keyStoreCli = EsKeyStoreCli.getInstance(esInstallation);\n\n      setupElasticsearchAuthentication(esInstallation, keyStoreCli);\n      setupElasticsearchHttpEncryption(esInstallation, keyStoreCli);\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java#L140-L176","documentation":"Before writing new Elasticsearch config files, pruneElasticsearchConfDirectory deletes any existing temporary conf directory using FileUtils2.deleteDirectory. If that deletion throws IOException (locked files, permissions, I/O errors), it is wrapped in this IllegalStateException because stale ES configuration would corrupt the next launch.","triggerScenarios":"writeConfFiles() -> pruneElasticsearchConfDirectory() when confDir.exists() but FileUtils2.deleteDirectory(confDir) throws IOException — e.g. a file in the temp ES conf dir is held open or is read-only.","commonSituations":"Previous SonarQube process still running and holding files in the temp dir; read-only or permission-denied temp directory; antivirus/indexers locking files on Windows; leftover root-owned files after running as a different user.","solutions":["Ensure no old SonarQube/Elasticsearch process is still running, then delete <temp>/conf manually.","Fix ownership/permissions on the sonar.path.temp directory for the sonarqube user.","Clear the temp directory entirely while the server is stopped.","On Windows, exclude the temp path from antivirus/indexing that may lock files."],"exampleFix":"$ sudo systemctl stop sonarqube\n$ ps aux | grep -i elasticsearch   # kill stragglers\n$ rm -rf /opt/sonarqube/temp/conf\n$ sudo systemctl start sonarqube","handlingStrategy":"retry","validationCode":"File conf = new File(tempDir, \"conf\");\nif (conf.exists() && !isDeletable(conf)) {\n    throw new IllegalStateException(\"Temp ES conf dir locked/undeletable: \" + conf);\n}","typeGuard":null,"tryCatchPattern":"try { launcher.launch(...); } catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Could not delete Elasticsearch\")) { cleanTempDir(); retry(); }\n}","preventionTips":["Stop all old SonarQube/ES processes before restarting the server.","Clear sonar.path.temp regularly while the server is down.","Exclude the temp directory from antivirus/indexing on Windows.","Run the server consistently as the same user to avoid foreign-owned temp files."],"tags":["filesystem","elasticsearch","temp-directory"],"backgroundTag":"file-write-failed","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}