java.net.SocketTimeoutException when building Docker image on CircleCI

Hey everyone, I’m facing an issue with building my Micronaut application in CircleCI. It’s a Micronaut 2.5.4 application with Picocli and uses Java 11.

The build step that is failing on CircleCI is ./gradlew dockerBuildNative . I’m able to run the command and build a GraalVM native Docker image on my local computer fine. On CircleCI the output is as follows:

Step 7/11 : RUN native-image -H:Class=thub.event.scheduler.ThubEventSchedulerCliJobCommand -H:Name=application --no-fallback -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar
 ---> Running in bf1dbeb5eba4
[application:26]    classlist:   9,573.75 ms,  0.96 GB
[application:26]        (cap):   1,104.57 ms,  0.96 GB
[application:26]        setup:   4,832.68 ms,  0.96 GB

Error during callback
java.net.SocketTimeoutException: Read timed out
    at com.bmuschko.gradle.docker.shaded.org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:149)
    at com.bmuschko.gradle.docker.shaded.org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
    at com.bmuschko.gradle.docker.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.getChunkSize(ChunkedInputStream.java:260)
    at com.bmuschko.gradle.docker.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.nextChunk(ChunkedInputStream.java:221)
    at com.bmuschko.gradle.docker.shaded.org.apache.hc.core5.http.impl.io.ChunkedInputStream.read(ChunkedInputStream.java:182)
    at com.bmuschko.gradle.docker.shaded.org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:135)
    at com.bmuschko.gradle.docker.shaded.com.fasterxml.jackson.core.json.UTF8StreamJsonParser._loadMore(UTF8StreamJsonParser.java:219)
    at com.bmuschko.gradle.docker.shaded.com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd2(UTF8StreamJsonParser.java:3005)
    at com.bmuschko.gradle.docker.shaded.com.fasterxml.jackson.core.json.UTF8StreamJsonParser._skipWSOrEnd(UTF8StreamJsonParser.java:3000)
    at com.bmuschko.gradle.docker.shaded.com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:716)
    at com.bmuschko.gradle.docker.shaded.com.fasterxml.jackson.databind.MappingIterator.hasNextValue(MappingIterator.java:243)
    at com.github.dockerjava.core.DefaultInvocationBuilder$JsonSink.accept(DefaultInvocationBuilder.java:314)
    at com.github.dockerjava.core.DefaultInvocationBuilder$JsonSink.accept(DefaultInvocationBuilder.java:298)
    at com.github.dockerjava.core.DefaultInvocationBuilder.lambda$executeAndStream$1(DefaultInvocationBuilder.java:275)

> Task :dockerBuildNative FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':dockerBuildNative'.
> java.net.SocketTimeoutException: Read timed out

My CircleCI job and the full output can be seen here

It did successfully build once on CircleCI out of the nearly 20 times it has run; it’s not clear to me why the job succeed that one time it did.

I’m hoping someone else has a Micronaut application that they are successfully building with dockerBuildNative on CircleCI and they can point me to the right environment variables and/or Docker image to use on CircleCI (I’m currently using cimg/openjdk:11.0).

From the searching I have done, it looks like I need to increase the socket timeout on the underlying docker-java calls but it doesn’t appear there’s any way to do it that I know of. There was a request in 2016 to add an enhancement to the gradle-docker-plugin to be able to specify those timeouts.