GoogleContainerTools / jib

🏗 Build container images for your Java applications.
Apache License 2.0
13.68k stars 1.44k forks source link

Investigate SingleProjectIntegrationTest#testBuild_dockerClient getting stuck indefinitely #4311

Closed mpeddada1 closed 2 weeks ago

mpeddada1 commented 1 month ago

Officially moving https://github.com/GoogleContainerTools/jib/pull/4299 to an issue for better tracking.

The SingleProjectIntegrationTest#testBuild_dockerClient test is getting stuck indefinitely with no progress:

2024-08-26T10:48:27.892-0400 [DEBUG] [TestEventLogger] com.google.cloud.tools.jib.gradle.SingleProjectIntegrationTest > testBuild_dockerClient STARTED
2024-08-26T10:48:37.334-0400 [LIFECYCLE] [org.gradle.cache.internal.DefaultFileLockManager] 
2024-08-26T10:48:37.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-08-26T10:48:37.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-08-26T10:48:37.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2024-08-26T10:48:37.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-08-26T10:48:37.335-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-08-26T10:48:37.335-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2024-08-26T10:48:47.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-08-26T10:48:47.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-08-26T10:48:47.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2024-08-26T10:48:47.335-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-08-26T10:48:47.335-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-08-26T10:48:47.335-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
2024-08-26T10:48:57.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
2024-08-26T10:48:57.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired on daemon addresses registry.
2024-08-26T10:48:57.334-0400 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.
. . .

I'm able to reproduce this locally as well with ./gradlew :jib-gradle-plugin:integrationTest --tests com.google.cloud.tools.jib.gradle.SingleProjectIntegrationTest.testBuild_dockerClient.

Where is it getting stuck?

It gets stuck at this line: https://github.com/GoogleContainerTools/jib/blob/ff15988e5eb36c686e7db47abb31bdc15c88f44a/jib-core/src/main/java/com/google/cloud/tools/jib/docker/CliDockerClient.java#L196

Other Observations

Related issues: https://github.com/GoogleContainerTools/jib/issues/4046

chanseokoh commented 1 month ago

Does it need the same fix as in #4048?

mpeddada1 commented 1 month ago

Thanks for the link! Hm after trying this out locally, it looks like the same logic as in #4048 still results in the test getting stuck indefinitely (at CharStreams.toString(stdout) now) :

   // Runs 'docker info'.
    Process infoProcess =  docker("info", "-f", "{{json .}}");
    try (InputStreamReader stdout =
        new InputStreamReader(infoProcess.getInputStream(), StandardCharsets.UTF_8)) {

      // CharStreams.toString() will block until the end of stream is reached.
      String output = CharStreams.toString(stdout);

      if (infoProcess.waitFor() != 0) {
        throw new IOException(
            "'docker inspect' command failed with error: " + getStderrOutput(infoProcess));
      }
   return JsonTemplateMapper.readJson(output, DockerInfoDetails.class);

Screenshot 2024-09-27 at 4 08 16 PM

mpeddada1 commented 1 month ago

After digging a little further and experimenting with the examples/helloworld sample, it appears that this issue doesn't occur when the following setup is used:

plugins {
  id 'java'
  id 'com.google.cloud.tools.jib' version '3.4.3'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
  mavenCentral()
}

dependencies {
  implementation 'com.google.guava:guava:23.6-jre'
}

jib {
  from {
    image = "openjdk:8"
    platforms {
      platform {
        architecture = "arm64"
        os = "linux"
      }
      platform {
        architecture = "amd64"
        os = "linux"
      }
    }
  }
  to {
    image = "docker-build-test"
  }
}

However, it does end up getting indefinitely stuck when the custom jib.dockerClient is used (as done in the test).