问题
We have a problem similar to those already discussed in Sonar analysis fails with SocketTimeoutException and Read timed out on SonarQube analysis but it happens to us in version 5.6.2. We have a large number of sonar analyses as a series of nightly builds starting at midnight and ending in the early morning. Only the first analysis (sometimes the first couple of analyses) are affected by a SocketTimeoutException during the upload of the report:
[exec] 00:15:33.724 DEBUG: Upload report
[exec] 00:16:34.065 INFO: ------------------------------------------------------------------------
[exec] 00:16:34.065 INFO: EXECUTION FAILURE
[exec] 00:16:34.065 INFO: ------------------------------------------------------------------------
[exec] 00:16:34.065 INFO: Total time: 1:28.329s
[exec] 00:16:34.320 ERROR: Error during SonarQube Scanner execution
[exec] java.lang.IllegalStateException: Fail to request http://mysonar:9000/sonar/api/ce/submit?projectKey=myproject&projectName=myproject
[exec] at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:212)
[exec] at org.sonarqube.ws.client.HttpConnector.post(HttpConnector.java:175)
[exec] at org.sonarqube.ws.client.HttpConnector.call(HttpConnector.java:146)
[exec] at org.sonar.batch.bootstrap.BatchWsClient.call(BatchWsClient.java:67)
[exec] at org.sonar.batch.report.ReportPublisher.upload(ReportPublisher.java:172)
[exec] at org.sonar.batch.report.ReportPublisher.execute(ReportPublisher.java:127)
[exec] at org.sonar.batch.phases.PublishPhaseExecutor.publishReportJob(PublishPhaseExecutor.java:64)
[exec] at org.sonar.batch.phases.PublishPhaseExecutor.executeOnRoot(PublishPhaseExecutor.java:51)
[exec] at org.sonar.batch.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:86)
[exec] at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:192)
[exec] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
[exec] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
[exec] at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:241)
[exec] at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:236)
[exec] at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:226)
[exec] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
[exec] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
[exec] at org.sonar.batch.task.ScanTask.execute(ScanTask.java:47)
[exec] at org.sonar.batch.task.TaskContainer.doAfterStart(TaskContainer.java:86)
[exec] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:142)
[exec] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:127)
[exec] at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:106)
[exec] at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:119)
[exec] at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:62)
[exec] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[exec] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[exec] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[exec] at java.lang.reflect.Method.invoke(Method.java:498)
[exec] at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
[exec] at com.sun.proxy.$Proxy0.execute(Unknown Source)
[exec] at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:233)
[exec] at org.sonarsource.scanner.api.EmbeddedScanner.runAnalysis(EmbeddedScanner.java:151)
[exec] at org.sonarsource.scanner.cli.Main.runAnalysis(Main.java:110)
[exec] at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
[exec] at org.sonarsource.scanner.cli.Main.main(Main.java:61)
[exec] Caused by: java.net.SocketTimeoutException: timeout
[exec] at okio.Okio$3.newTimeoutException(Okio.java:207)
[exec] at okio.AsyncTimeout.exit(AsyncTimeout.java:261)
[exec] at okio.AsyncTimeout$2.read(AsyncTimeout.java:215)
[exec] at okio.RealBufferedSource.indexOf(RealBufferedSource.java:306)
[exec] at okio.RealBufferedSource.indexOf(RealBufferedSource.java:300)
[exec] at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196)
[exec] at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191)
[exec] at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:79)
[exec] at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:909)
[exec] at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:93)
[exec] at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:894)
[exec] at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:748)
[exec] at com.squareup.okhttp.Call.getResponse(Call.java:277)
[exec] at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:234)
[exec] at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:196)
[exec] at com.squareup.okhttp.Call.execute(Call.java:79)
[exec] at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:209)
[exec] ... 34 more
[exec] Caused by: java.net.SocketException: Socket closed
[exec] at java.net.SocketInputStream.read(SocketInputStream.java:204)
[exec] at java.net.SocketInputStream.read(SocketInputStream.java:141)
[exec] at okio.Okio$2.read(Okio.java:139)
[exec] at okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
[exec] ... 48 more
[exec] 00:16:34.322 ERROR:
[exec] 00:16:34.322 ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
[exec] 00:16:34.320 INFO: Final Memory: 59M/426M
[exec] 00:16:34.320 INFO: ------------------------------------------------------------------------
[exec] Result: 1
[echo] Sonar execution failed, please check the log
Normally, the upload takes just milliseconds (around 200ms for the largest projects), while in this case a timeout seems to occur after 60 seconds (upload at 00:15:33, failure at 00:16:34). At the same time, the access.log
at the server shows a very strange pattern: the POST /sonar/api/ce/submit
arrives at the server at 00:21:39, six minutes after the initial upload request and five minutes after the client received the TimeoutException (and the clocks of the client and server are perfectly in sync).
10.0.206.160 - - [13/Mar/2017:00:15:09 +0100] "GET /sonar/batch/project.protobuf?key=myprojectkey HTTP/1.1" 200 2556 "-" "SonarQubeRunner/2.7"
10.0.206.160 - - [13/Mar/2017:00:15:09 +0100] "GET /sonar/api/qualityprofiles/search.protobuf?projectKey=myprojectkey HTTP/1.1" 200 909 "-" "SonarQubeRunner/2.7"
10.0.206.160 - - [13/Mar/2017:00:21:39 +0100] "POST /sonar/api/ce/submit?projectKey=myprojectkey&projectName=myproject HTTP/1.1" 200 60 "-" "SonarQubeRunner/2.7"
Even stranger, the Sonar GUI actually presents all the analysis results with the timestamp of the initial upload time (at the client, 00:15) and the Background Tasks view shows the following timestamps: submitted=12:15:33 AM, started=12:22:03 AM, finished=12:22:08 AM. Basically, everything works from an analysis point of view, but still the build still fails due to the timeout exception.
回答1:
This problem is particular to our setup. It was caused by a Sonar database backup running simultaneously with some of the nightly builds. During the ~20min that mysqldump
is running to create a backup, the Sonar services get totally unresponsive and results in a SocketTimeoutException when clients try uploading the analysis report.
Solution in this case: move the DB backup to a time when Sonar is idle.
来源:https://stackoverflow.com/questions/42781303/upload-of-sonar-report-fails-due-to-sockettimeoutexception