[Project Analysis] Error Details java.lang.OutOfMemoryError: Java heap of space

Hi,
SonarQube: Community Edition Version 10.3 (build 82913)
Sonar-scanner: 5.0.1.3006
sonar.properties:
sonar.web.javaOpts=-Xmx4g -Xms512m -XX:+HeapDumpOnOutOfMemoryError
sonar.ce.javaOpts=-Xmx4g -Xms512m -XX:+HeapDumpOnOutOfMemoryError
the sonarqube server: Operating System: Ubuntu 22.04.3 LTS, 4cpu, 16Gb ram
the server i scanned: Operating System: Ubuntu 18.04.6 LTS, 2cpu, 8Gb ram

After a succesfull scan, i got the message “analysis has failed”
when i go into task background and look at the error details i have only " Error Details
java.lang.OutOfMemoryError: Java heap space"

and on the server i scanned i got this:

INFO: Analysis report generated in 8959ms, dir size=1.2 GB
INFO: Analysis report compressed in 80433ms, zip size=242.7 MB
INFO: Analysis report uploaded in 13747ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at: http://x.x.x.x:9000/dashboard?id=###
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://x.x.x.x:9000/api/ce/task?id=###
INFO: Analysis total time: 23:30.032 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 23:31.465s
INFO: Final Memory: 36M/127M
INFO: ------------------------------------------------------------------------

so idk what to do to got the results on the web interface thx for help

ps: i replaced sensitive info by # and x

Hey there.

Can you verify that you see the updated Compute Engine heap space (based on sonar.ce.javaOpts) in your global Administration > System?

I think it didn’t take any modification, seeing what it is displayed

I think that’s the problem then.

Once you configure these properties you need to restart your SonarQube server (./sonar.sh restart) for them to take effect. Can you try that?

./sonar.sh restart
/usr/bin/java
Gracefully stopping SonarQube…
SonarQube was not running.
Starting SonarQube…
Started SonarQube.
root@server:/opt/sonarqube/bin/linux-x86-64# ./sonar.sh status
/usr/bin/java
Removed stale pid file: ./SonarQube.pid
SonarQube is not running.

idk why it doesn’t want to correctly restart

What do the logs say?

sorry the precedent logs where the rong ones
i think this one is the good one

2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Stopping SonarQube
2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Sonarqube has been requested to stop
2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Stopping [Compute Engine] process...
2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Process[Compute Engine] is stopped
2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Stopping [Web Server] process...
2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Process[Web Server] is stopped
2024.02.13 07:16:58 INFO  app[][o.s.a.SchedulerImpl] Stopping [ElasticSearch] process...
2024.02.13 07:16:59 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:16:59 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 143
2024.02.13 07:16:59 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2024.02.13 07:17:00 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.13 07:17:00 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:44545]
2024.02.13 07:17:00 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.02.13 07:17:00 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.13 07:17:00 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.13 07:17:00 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:42721]
2024.02.13 07:17:00 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.02.13 07:17:00 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.13 07:17:02 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 78
2024.02.13 07:17:02 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:17:02 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2024.02.13 07:17:03 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2024.02.13 07:17:03 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:17:03 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2024.02.13 07:18:31 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.13 07:18:31 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:45845]
2024.02.13 07:18:31 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.02.13 07:18:31 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.13 07:18:33 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2024.02.13 07:18:33 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:18:33 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2024.02.13 07:20:01 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.13 07:20:01 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:33467]
2024.02.13 07:20:01 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.02.13 07:20:01 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.13 07:20:04 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2024.02.13 07:20:04 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:20:04 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2024.02.13 07:21:54 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.13 07:21:54 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:45973]
2024.02.13 07:21:54 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.02.13 07:21:54 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.13 07:21:57 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2024.02.13 07:21:57 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:21:57 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped
2024.02.13 07:22:36 INFO  app[][o.s.a.AppFileSystem] Cleaning or creating temp directory /opt/sonarqube/temp
2024.02.13 07:22:36 INFO  app[][o.s.a.es.EsSettings] Elasticsearch listening on [HTTP: 127.0.0.1:9001, TCP: 127.0.0.1:46337]
2024.02.13 07:22:36 INFO  app[][o.s.a.ProcessLauncherImpl] Launch process[ELASTICSEARCH] from [/opt/sonarqube/elasticsearch]: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xms4m -Xmx64m -XX:+UseSerialGC -Dcli.name=server -Dcli.script=./bin/elasticsearch -Dcli.libs=lib/tools/server-cli -Des.path.home=/opt/sonarqube/elasticsearch -Des.path.conf=/opt/sonarqube/temp/conf/es -Des.distribution.type=tar -cp /opt/sonarqube/elasticsearch/lib/*:/opt/sonarqube/elasticsearch/lib/cli-launcher/* org.elasticsearch.launcher.CliToolLauncher
2024.02.13 07:22:37 INFO  app[][o.s.a.SchedulerImpl] Waiting for Elasticsearch to be up and running
2024.02.13 07:22:39 WARN  app[][o.s.a.p.AbstractManagedProcess] Process exited with exit value [ElasticSearch]: 1
2024.02.13 07:22:39 INFO  app[][o.s.a.SchedulerImpl] Process[ElasticSearch] is stopped
2024.02.13 07:22:39 INFO  app[][o.s.a.SchedulerImpl] SonarQube is stopped

There should be some logs in es.log telling you why it failed to start.

2024.02.14 10:46:45 ERROR es[][o.e.b.Elasticsearch] fatal exception while booting Elasticsearch
java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Elasticsearch.initializeNatives(Elasticsearch.java:282) ~[elasticsearch-8.11.0.jar:?]
	at org.elasticsearch.bootstrap.Elasticsearch.initPhase2(Elasticsearch.java:167) ~[elasticsearch-8.11.0.jar:?]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:72) ~[elasticsearch-8.11.0.jar:?]

i know that we can’t run it as root but other users cant run the sonar.sh even with all rights on the file

What happens when you try?

/usr/bin/java
Gracefully stopping SonarQube...
rm: cannot remove './SonarQube.pid': Permission denied
Removed stale pid file: ./SonarQube.pid
SonarQube was not running.
Starting SonarQube...
rm: cannot remove './SonarQube.pid': Permission denied
Removed stale pid file: ./SonarQube.pid
./sonar.sh: 165: cannot create ./SonarQube.pid: Permission denied
./sonar.sh: 164: cannot create ../../logs/nohup.log: Permission denied
rm: cannot remove './SonarQube.pid': Permission denied
Removed stale pid file: ./SonarQube.pid
Failed to start SonarQube.

It really seems like a permissions issue. What permissions did you apply to the folder? Did you do so recursively?

-rwxrwxrwx 1 root root 7192 Feb 5 09:28 sonar.sh