OutOfMemoryError: Java heap space with Elasticsearch client after sonar-scanner uploads report


(Alain O'Dea) #1
  • versions used

SonarQube 7.3.0.15553

  • error observed

The most identifying snippet appears to be this in sonar.log:

elasticsearch[_client_][generic] OutOfMemoryError: Java heap space

In Jenkins, sonar-scanner logs this:

INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarqube.example.com/dashboard?id=example
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 https://sonarqube.example.com/api/ce/task?id=AWZaOppN90-T_I217-Og

But visiting the “you can browse” link shows a red error banner in SonarQube stating:

The last analysis has failed.

And the “more about the report processing” link reports this:

{
  "task": {
    "id": "AWZaOppN90-T_I217-Og",
    "type": "REPORT",
    "componentId": "AWZaOppN90-T_I217-Og",
    "componentKey": "example",
    "componentName": "Example",
    "componentQualifier": "TRK",
    "status": "FAILED",
    "submittedAt": "2018-10-09T19:08:03+0000",
    "submitterLogin": "admin",
    "startedAt": "2018-10-09T19:08:05+0000",
    "executedAt": "2018-10-09T19:13:41+0000",
    "executionTimeMs": 336334,
    "logs": false,
    "errorMessage": "Java heap space",
    "hasScannerContext": true,
    "organization": "default-organization"
  }
}

<SONAR_HOME>/logs/ce.log shows this:

2018.10.09 19:13:41 ERROR ce[AWZaOppN90-T_I217-Og][o.s.c.t.CeWorkerImpl] Failed to execute task AWZaOppN90-T_I217-Og
java.lang.OutOfMemoryError: Java heap space
        at com.google.protobuf.CodedInputStream$StreamDecoder.<init>(CodedInputStream.java:2080)
        at com.google.protobuf.CodedInputStream$StreamDecoder.<init>(CodedInputStream.java:2056)
        at com.google.protobuf.CodedInputStream.newInstance(CodedInputStream.java:86)
        at com.google.protobuf.CodedInputStream.newInstance(CodedInputStream.java:77)
        at com.google.protobuf.AbstractParser.parsePartialFrom(AbstractParser.java:220)
        at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(AbstractParser.java:262)
        at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(AbstractParser.java:268)
        at com.google.protobuf.AbstractParser.parsePartialDelimitedFrom(AbstractParser.java:49)
        at org.sonar.core.util.Protobuf$StreamIterator.doNext(Protobuf.java:163)
        at org.sonar.core.util.Protobuf$StreamIterator.doNext(Protobuf.java:151)
        at org.sonar.core.util.CloseableIterator.bufferNext(CloseableIterator.java:96)
        at org.sonar.core.util.CloseableIterator.hasNext(CloseableIterator.java:87)
        at org.sonar.ce.task.projectanalysis.issue.TrackerRawInputFactory$RawLazyInput.loadIssues(TrackerRawInputFactory.java:108)
        at org.sonar.core.issue.tracking.LazyInput.getIssues(LazyInput.java:50)
        at org.sonar.core.issue.tracking.Tracker.track(Tracker.java:30)
        at org.sonar.ce.task.projectanalysis.issue.TrackerExecution.track(TrackerExecution.java:42)
        at org.sonar.ce.task.projectanalysis.issue.IssueTrackingDelegator.track(IssueTrackingDelegator.java:54)
        at org.sonar.ce.task.projectanalysis.issue.IntegrateIssuesVisitor.visitAny(IntegrateIssuesVisitor.java:64)
        at org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorWrapper.visitAny(TypeAwareVisitorWrapper.java:82)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visitNode(VisitorsCrawler.java:117)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visitImpl(VisitorsCrawler.java:100)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visit(VisitorsCrawler.java:72)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visitChildren(VisitorsCrawler.java:110)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visitImpl(VisitorsCrawler.java:97)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visit(VisitorsCrawler.java:72)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visitChildren(VisitorsCrawler.java:110)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visitImpl(VisitorsCrawler.java:97)
        at org.sonar.ce.task.projectanalysis.component.VisitorsCrawler.visit(VisitorsCrawler.java:72)
        at org.sonar.ce.task.projectanalysis.step.ExecuteVisitorsStep.execute(ExecuteVisitorsStep.java:51)
        at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:69)
        at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:55)
        at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)

<SONAR_HOME>/logs/sonar.log shows this:

Exception in thread "elasticsearch[_client_][generic][T#4]" java.lang.OutOfMemoryError: Java heap space
        at java.util.zip.InflaterInputStream.<init>(InflaterInputStream.java:88)
        at java.util.zip.ZipFile$ZipFileInflaterInputStream.<init>(ZipFile.java:408)
        at java.util.zip.ZipFile.getInputStream(ZipFile.java:389)
        at java.util.jar.JarFile.getInputStream(JarFile.java:447)
        at sun.misc.URLClassPath$JarLoader$2.getInputStream(URLClassPath.java:977)
        at sun.misc.Resource.cachedInputStream(Resource.java:77)
        at sun.misc.Resource.getByteBuffer(Resource.java:160)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:454)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.elasticsearch.ElasticsearchException.<clinit>(ElasticsearchException.java:1039)
        at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:950)
        at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Exception in thread "Thread-5" java.lang.OutOfMemoryError: Java heap space
        at java.util.jar.Manifest$FastInputStream.<init>(Manifest.java:332)
        at java.util.jar.Manifest$FastInputStream.<init>(Manifest.java:327)
        at java.util.jar.Manifest.read(Manifest.java:195)
        at java.util.jar.Manifest.<init>(Manifest.java:69)
        at java.util.jar.JarFile.getManifestFromReference(JarFile.java:199)
        at java.util.jar.JarFile.getManifest(JarFile.java:180)
        at sun.misc.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:981)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:450)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at org.apache.logging.log4j.message.ParameterizedMessageFactory.newMessage(ParameterizedMessageFactory.java:103)
        at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2028)
        at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1908)
        at org.apache.logging.log4j.spi.AbstractLogger.warn(AbstractLogger.java:2670)
        at org.elasticsearch.transport.TransportService$Adapter.checkForTimeout(TransportService.java:830)
        at org.elasticsearch.transport.TransportService$Adapter.onResponseReceived(TransportService.java:812)
        at org.elasticsearch.transport.TcpTransport.messageReceived(TcpTransport.java:1385)
        at org.elasticsearch.transport.netty4.Netty4MessageChannelHandler.channelRead(Netty4MessageChannelHandler.java:74)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:297)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:413)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
  • steps to reproduce

After a complete scan of our main codebase, this happens every time sonar-scanner attempts to report back. This started happening when we added JaCoCo.

  • potential workaround

Remove JaCoCo reports and analysis. That’s not a great option as code coverage is an important quality gate we want to be running.


(Alain O'Dea) #2

Here’s what appears to have worked. I’m not sure it is a good idea or efficient use of memory.

<SONAR_HOME>/conf/sonar.properties:

sonar.ce.javaOpts=-Xmx2g

It worked to get my analysis through.