# Elasticsearch-related issues

## Recovering from Elasticsearch read-only indices <a href="#recovering-from-elasticsearch-read-only-indices" id="recovering-from-elasticsearch-read-only-indices"></a>

You may encounter issues with Elasticsearch (ES) indices becoming locked in read-only mode. ES requires free disk space available and implements a safety mechanism to prevent the disk from being flooded with index data that:

* locks all indices in read-only mode when the 95% used disk usage watermark is reached.

ES shows warnings in the logs as soon as disk usage reaches 85% and 90%. At 95% usage and above, indices turning read-only causes errors in the web and compute engine.

Freeing disk space will *not* automatically make the indices return to read-write. To make indices read-write, you also need to:

* restart SonarQube Community Build.

SonarQube Community Build’s built-in resilience mechanism allows SonarQube Community Build to eventually recover from the indices being behind data in the DB (this process can take a while).

If you still have inconsistencies, you’ll need to rebuild the indices (this operation can take a long time depending on the number of issues and components):

1. Stop SonarQube Community Build.
2. Delete the `data/es8` directory.
3. Restart SonarQube Community Build.

## Failed background tasks during reindexing <a href="#failed-tasks-during-reindexing" id="failed-tasks-during-reindexing"></a>

During Elasticsearch reindexing, you may have failed tasks in your branches or pull requests:

* If you only have a few failed tasks, you can reanalyze your branch or pull request. You may want to use web services to remove branches and pull requests that can’t be reanalyzed because they have been removed from version control.
* If you have many failed tasks, you may want to delete your Elasticsearch directory and reindex again. To do so, see [#forcing-es-reindex](https://docs.sonarsource.com/sonarqube-community-build/maintenance/reindexing#forcing-es-reindex "mention") for more details.

If background tasks of type **Project Data Reload** fail for a particular project, see the [#reindexing-single-project](https://docs.sonarsource.com/sonarqube-community-build/maintenance/reindexing#reindexing-single-project "mention") article.

## Exception java.lang.RuntimeException: cannot run elasticsearch as root <a href="#elasticsearch" id="elasticsearch"></a>

SonarQube Community Build starts an Elasticsearch process, and the same account that is running SonarQube Community Build itself will be used for the Elasticsearch process. Since Elasticsearch cannot be run as root, that means SonarQube Community Build can’t be either. You must choose some other, non-root account with which to run SonarQube Community Build, preferably an account dedicated to the purpose.

## Exception: Failed to allocate closure <a href="#exception-failed-to-allocate-closure" id="exception-failed-to-allocate-closure"></a>

This issue is only relevant to Linux. See [Ensure JNA temporary directory permits executables](https://www.elastic.co/docs/deploy-manage/deploy/self-managed/executable-jna-tmpdir) for detailed information. There are two options to ensure the JNA temp directory matches Elasticsearch’s requirements:

1. Remove `noexec` flag on the `/tmp` or wherever `sonar.path.temp` is set to, e.g. `mount -o remount,rw,`exec`/tmp`
2. Change ES temp directory to a different location that is not so restrictive via `sonar.path.temp`, which will define `-Djna.tmpdir`

### Error: `Unable to open socket file /tmp/.java_pid<PID>` <a href="#error-unable-to-open-socket-file-tmp-.java_pid-less-than-pid-greater-than" id="error-unable-to-open-socket-file-tmp-.java_pid-less-than-pid-greater-than"></a>

SonarQube Community Build 26.1 and later includes Elasticsearch 8.x, which requires read and write access to the `/tmp` directory. This is a requirement from Elasticsearch itself and cannot be disabled. For more information and a solution, see [#elasticsearch-filesystem-requirements](https://docs.sonarsource.com/sonarqube-community-build/server-installation/pre-installation/linux#elasticsearch-filesystem-requirements "mention").

## Elasticsearch crashes at start up on SonarQube Community Build 26.1 and higher

If you are updating to SonarQube Community Build 26.1 or higher on SUSE Linux, and Elasticsearch crashes at startup generating a Java `UnsatisfiedLinkError` error:

1. Make sure you have JDK, Java version 21 or 25 installed on your system,
2. Install development tools on your JDK by executing the following command: `sudo zypper install java-21-openjdk-devel`

## Related pages <a href="#related-pages" id="related-pages"></a>

* [server-logs](https://docs.sonarsource.com/sonarqube-community-build/server-update-and-maintenance/troubleshooting/server-logs "mention")
* [performance-issues](https://docs.sonarsource.com/sonarqube-community-build/server-update-and-maintenance/troubleshooting/performance-issues "mention")
* [database-related-issues](https://docs.sonarsource.com/sonarqube-community-build/server-update-and-maintenance/troubleshooting/database-related-issues "mention")
