java.net.SocketException: Broken pipe (Write failed) when running analysis from terminal

Hello,

our company uses SonarCloud, and we are in a phase of setting up a proper CI/CD pipeline. For now, we run the analysis manually from the command line

mvn verify -Pjacoco-report jacoco:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -DnecessaryParameters

This works fine, but for one of the branch we are getting an exception at the end of the maven job:

[INFO] CPD Executor CPD calculation finished (done) | time=4660ms
[INFO] Analysis report generated in 5560ms, dir size=172 MB
[INFO] Analysis report compressed in 31823ms, zip size=63 MB
[INFO] Analysis report uploaded in 67215ms
[INFO] ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=XXX
[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://sonarcloud.io/api/ce/task?id=AYooUsDkDXwWrxZaOIDd
[java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed)]
[WARNING] Failed to publish the sensor cache
[INFO] Time spent writing ucfgs 372ms
[INFO] Analysis total time: 27:11.556 s

The analysis is not visible in our SonarCloud project. I tried to run the maven job with debug flag to get more insight, but I do not see anything out of ordinary.

INFO] 10:56:31.113 Analysis report generated in 5316ms, dir size=172 MB
[INFO] 10:57:01.210 Analysis report compressed in 30097ms, zip size=63 MB
[INFO] 10:57:01.210 Analysis report generated in /XXX/target/sonar/scanner-report
[DEBUG] 10:57:01.210 Upload report
[DEBUG] 10:59:01.637 POST 200 https://sonarcloud.io/api/ce/submit?XXX | time=120423ms
[INFO] 10:59:01.651 Analysis report uploaded in 120441ms
[DEBUG] 10:59:01.658 Report metadata written to XXX/target/sonar/report-task.txt
[INFO] 10:59:01.658 ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=XXX
[INFO] 10:59:01.659 Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] 10:59:01.659 More about the report processing at https://sonarcloud.io/api/ce/task?id=AYooDk7jC5kvvPhJ66-L
[DEBUG] 10:59:10.629 GET 200 https://ea6ne4j2sb.execute-api.eu-central-1.amazonaws.com/current/v1/sensor_cache/prepare_write?organization=XXX&project=XXX | time=587ms
[DEBUG] 11:00:23.929 PUT 200 https://sc-cleancode-sensorcache-eu-central-1-prod.s3.amazonaws.com...XXX | time=73297ms
[INFO] 11:00:23.931 Sensor cache published successfully
[DEBUG] 11:00:23.943 Post-jobs : 
[DEBUG] 11:00:23.964 the bridge server will shutdown
[DEBUG] 11:00:28.967 the bridge server closed
[INFO] 11:00:28.973 Time spent writing ucfgs 346ms
[INFO] 11:00:31.639 Analysis total time: 25:15.214 s
[INFO] ------------------------------------------------------------------------
[DEBUG] Shutting down adapter factory; available factories [file-lock, rwlock-local, semaphore-local, noop]; available name mappers [discriminating, file-gav, file-hgav, file-static, gav, static]
[DEBUG] Shutting down 'file-lock' factory
[DEBUG] Shutting down 'rwlock-local' factory
[DEBUG] Shutting down 'semaphore-local' factory
[DEBUG] Shutting down 'noop' factory

While the error is not visible in the logs with the debug flag logging on the analysis is not visible in our SonarCloud project.

Thank you!
Tomas

That’s a really weird set of behavior (it works when the DEBUG flag is on, but analysis doesn’t get published…)

Are you sure this is repeatable? If you unset the DEBUG flag do you still get the broken pipe message?

Hi Colin,

thank you for your response! The error is not visible in the logs when DEBUG flag is not, but the analysis is not visible.
I have rerun the analysis on my localhost multiple times with the same error.
Just to confirm, if branch is called feature/IP-15695_unused_private_field_pt2 the parameter to pass to the maven build is -Dsonar.branch.name=feature/IP-15695_unused_private_field_pt2
I run the analysis on a new branch and the analysis was posted under master branch and the new branch “feature/IP-15695_unused_private_field_pt2” is not visible under branches

Colin,

Unfortunately the same result for the new branch, seems like we are not able to create analysis for a new branch for the last 14 days

[INFO] CPD Executor CPD calculation finished (done) | time=14576ms
[INFO] Analysis report generated in 5340ms, dir size=172 MB
[INFO] Analysis report compressed in 30874ms, zip size=63 MB
[INFO] Analysis report uploaded in 119049ms
[INFO] ANALYSIS SUCCESSFUL, you can find the results at: https://sonarcloud.io/dashboard?id=healthgorilla_www
[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://sonarcloud.io/api/ce/task?id=AYos82XkC5kvvPhJ7WS-
[java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed), java.net.SocketException: Broken pipe (Write failed)]
[WARNING] Failed to publish the sensor cache
[INFO] Time spent writing ucfgs 403ms
[INFO] Analysis total time: 46:53.425 s

I was able to get the stack trace from the debugger

[ERROR] 11:13:11.998 Failed to publish the sensor cache
java.lang.IllegalStateException: Fail to request https://sc-cleancode-sensorcache-eu-central-1-prod.s3.amazonaws.com/AYj9owanNlDOHX_ny9NQ/AYj-FIIzF818vWKcgP8U/AYj-FIIzF818vWKcgP8U?params.....
	at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:230)
	at org.sonarqube.ws.client.HttpConnector.put(HttpConnector.java:179)
	at org.sonarqube.ws.client.HttpConnector.call(HttpConnector.java:127)
	at org.sonar.scanner.bootstrap.DefaultScannerWsClient.call(DefaultScannerWsClient.java:59)
	at org.sonar.scanner.sensor.cache.SensorCachePublisherImpl.publish(SensorCachePublisherImpl.java:66)
	at org.sonar.scanner.sensor.cache.ScannerWriteCacheImpl.publish(ScannerWriteCacheImpl.java:81)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:430)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:57)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:51)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy73.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute(ScannerBootstrapper.java:65)
	at org.sonarsource.scanner.maven.SonarQubeMojo.execute(SonarQubeMojo.java:108)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:342)
	at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:330)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:175)
	at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:76)
	at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:163)
	at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:160)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:827)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:272)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:195)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: java.net.SocketException: Broken pipe (Write failed)
	at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
	at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
	at java.base/sun.security.ssl.SSLSocketOutputRecord.deliver(SSLSocketOutputRecord.java:345)
	at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1305)
	at okio.OutputStreamSink.write(JvmOkio.kt:57)
	at okio.AsyncTimeout$sink$1.write(AsyncTimeout.kt:99)
	at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.kt:255)
	at okio.RealBufferedSink.write(RealBufferedSink.kt:146)
	at okhttp3.internal.http1.Http1ExchangeCodec$KnownLengthSink.write(Http1ExchangeCodec.kt:271)
	at okio.ForwardingSink.write(ForwardingSink.kt:29)
	at okhttp3.internal.connection.Exchange$RequestBodySink.write(Exchange.kt:218)
	at okio.RealBufferedSink.emitCompleteSegments(RealBufferedSink.kt:255)
	at okio.RealBufferedSink.writeAll(RealBufferedSink.kt:194)
	at okhttp3.RequestBody$Companion$asRequestBody$1.writeTo(RequestBody.kt:167)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.kt:59)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at org.sonarqube.ws.client.OkHttpClientBuilder.addHeaders(OkHttpClientBuilder.java:201)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:34)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
	at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
	at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154)
	at org.sonarqube.ws.client.HttpConnector.doCall(HttpConnector.java:228)
	... 51 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted
	Suppressed: java.net.SocketException: Broken pipe (Write failed)
		... 81 common frames omitted

Hi,

Sorry about that. The spam filter is a little over-zealous (crazy) sometimes. I’ve unflagged your posts.

 
Ann

1 Like

I think there are two issues here:

  • Analysis showing up under master when it should show up under a branch
  • Writing the sensor cache

Let’s focus on the first one:

Where are you configuring sonar.branch.name – can you share the exact command you’re executing or the specific file? I’m doubtful that it’s making its way to the scanner at all (it should be obvious from early on whether or not a branch is being considered in the analysis.

16:20:32.554 DEBUG: Could not detect any CI vendor
16:20:32.559 INFO: Load project settings for component key: 'colin-sonarsource_testbranch'
16:20:33.219 DEBUG: GET 200 https://sonarcloud.io/api/settings/values.protobuf?component=colin-sonarsource_testbranch | time=659ms
16:20:33.223 INFO: Load project settings for component key: 'colin-sonarsource_testbranch' (done) | time=664ms

Something as simple as a weird new line could be preventing it from reaching the scanner.

Hi Colin,

this issue seems to be resolved, I rerun the analysis today, and I’m no longer receive the SocketException, the branch with the analysis were correctly created in our SonarCloud project. Again, looking at the error stack trace, I assume the issue must have been resolved by a change in your cloud environment.

To answer your question, we run the analysis from terminal using this command

mvn verify -Pjacoco-report jacoco:report org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=XXX -Dsonar.token=XXX -Dsonar.branch.name=feature/IP-15591