Skip to content

BlockingProcessStreamReader.java doesn't log the error text and silently exits #9097

@jainsahab

Description

@jainsahab

BlockingProcessStreamReader.java is a separate thread which checks for blockUntil text to appear in it's constructor.
https://github.com/googleapis/java-core/blob/main/google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java#L47-L61

In cases where process is abruptly closed and resulted in non zero exit code, BlockingProcessStreamReader.java doesn't log the startup logs(which may contain the error information). This causes confusion to the end user.

Steps to reproduce

  • Run gcloud beta emulators datastore startss (notice the typo in command) to check the error text we get on stdout.
➜  java-core git:(gh_issue_1038) ✗ gcloud beta emulators datastore startss
ERROR: (gcloud.beta.emulators.datastore) Invalid choice: 'startss'.
Maybe you meant:
  gcloud beta emulators datastore start
  gcloud beta emulators datastore env-init
  gcloud beta emulators datastore env-unset
  gcloud beta emulators bigtable start
  gcloud beta emulators firestore start
  gcloud beta emulators pubsub start

To search the help text of gcloud commands, run:
  gcloud help -- SEARCH_TERMS
  • Execute below code and we can see that nothing is logged now.
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Logger;

public class Playground {

  public static void main(String[] args) throws IOException, InterruptedException {

    Process process = CommandWrapper.create()
        .setCommand(Arrays.asList("gcloud beta emulators datastore startss".split(" "))) // notice the typo in command
        .setRedirectErrorStream().start();
    BlockingProcessStreamReader blockingProcessStreamReader = BlockingProcessStreamReader.start(
        "test-playground", process.getInputStream(), "blockUntilOutput",
        Logger.getLogger(Playground.class.getName()));

    blockingProcessStreamReader.join();

    System.out.printf("Subprocess exit code: %d%n", process.exitValue()); // should print non zero value
  }

}

Ref: Similar issue happened in googleapis/java-datastore#355.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: p3Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions