Skip to content

google-cloud-compute: ImagesClient does not terminate, and hangs instead #10220

@Martiul

Description

@Martiul

Environment details

API: google-cloud-compute

OS type and version: MacOS Sonoma 14.2.1
Java version: 21 (temurin)
Version(s): 1.43.0

Steps to reproduce

  1. Add the following maven dependency to the pom.xml in a barebones Maven project:
<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-compute</artifactId>
  <version>1.43.0</version>
</dependency>
  1. Try to use ImagesClient
 try (ImagesClient imagesClient = ImagesClient.create(ImagesSettings.newBuilder().build())) {
    imagesClient.get(GetImageRequest.newBuilder()
        .setProject("foo")
        .setImage("bar").build());
  }
  1. Run Main in IntelliJ (no permissions are required)

Expected behaviour: The get() fails because of a lack of permissions and the program terminates.

	at com.google.api.gax.httpjson.HttpRequestRunnable.run(HttpRequestRunnable.java:118)
	... 6 more

Process finished with exit code 1

Actual behaviour: The get() fails because of a lack of permissions and the program does NOT terminate. It just hangs. (Indicated by the IntelliJ Run toolbar's STOP button still being clickable)

	at com.google.api.gax.httpjson.HttpRequestRunnable.run(HttpRequestRunnable.java:118)
	... 6 more

Code example

public class Main {
  public static void main(String[] args) throws Exception{
    testGce();
   }
   
   public static void testGce() {
    Image i = null;
    ImagesClient imagesClient = null;
    try {
      imagesClient = ImagesClient.create(ImagesSettings.newBuilder().build());
    } catch( Exception e) {
      System.out.println("Exception!");
    } finally {
      imagesClient.shutdown();
      imagesClient.shutdownNow();
      System.out.println("Is terminated: " + imagesClient.isTerminated());  // should be true
    }
  }   
 }

Stack trace

NA

External references such as API reference guides

NA

Any additional information below

For some context, I am developing a Spring Shell CLI tool, and one of the commands uses the GCE ImagesClient. Before, when a user ran the command successfully, the user would then be able to run another command. This was on google-cloud-compute 1.13.0. However, now when the user runs a command using the ImagesClient the command hangs, and the program ends after a 10minute idle timeout set by Spring Shell. I've been able to reproduce the issue on a barebones Maven project.

Additionally, I've tried using imagesClient.awaitTermination(10, TimeUnit.SECONDS); but this command still hangs.
Furthermore, I've used imagesClient.isTerminated() and have observed that in the previous versions, it would return true. But now it returns false.

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions