Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pub/Sub streaming pull swallows Throwables that are not Exceptions #1156

Open
elefeint opened this issue Jun 1, 2022 · 0 comments
Open

Pub/Sub streaming pull swallows Throwables that are not Exceptions #1156

elefeint opened this issue Jun 1, 2022 · 0 comments
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@elefeint
Copy link

elefeint commented Jun 1, 2022

This issue is a general case of the one in GoogleCloudPlatform/spring-cloud-gcp#1103. When user message processing results in a non-Exception Throwable (the two common usecases being assertion errors and system errors such as OutOfMemoryError), Pub/Sub client library effectively silently ignores the failure.
While the best practice is to avoid catching Throwable, in case of message processing it needs to be done -- the user application needs to have useful troubleshooting logs, and ideally the message ought to get nacked, as well. Of course, nacking with something like OutOfMemoryError won't reliably happen, but it's still worth an attempt.

Current behavior
Currently when user message processing code throws an Error, this MessageDispatcher code will pass the error on without catching, as the catch clause only applies to Exception. However, deliverMessageTask is a simple runnable that runs on a GAX thread. When the error bubbles up, the thread is returned to the thread pool.

Desired behavior
The catch block in MessageDispatcher should apply to any Throwable, so that ackReplySettableApiFuture.setException(e); can get set and processed as an error.

Environment details

  1. Library: Pub/Sub
  2. OS type and version: Linux
  3. Java version: 17.0.2
  4. version(s): 1.117.0

Steps to reproduce

A slightly modified code sample from docs demonstrates the issue:

public static void subscribeAsyncExample(String projectId, String subscriptionId) {
    ProjectSubscriptionName subscriptionName =
        ProjectSubscriptionName.of(projectId, subscriptionId);

    // Instantiate an asynchronous message receiver.
    MessageReceiver receiver =
        (PubsubMessage message, AckReplyConsumer consumer) -> {
          // Log incoming message, then throw a non-Exception Throwable
          System.out.println("Id: " + message.getMessageId());
          System.out.println("Data: " + message.getData().toStringUtf8());
          //consumer.ack();

          /****** This Error will disappear without a log; message won't be nacked and will time out *********/
          throw new Error("this Throwable will disappear");  
        };

    Subscriber subscriber = null;
    try {
      subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
      // Start the subscriber.
      subscriber.startAsync().awaitRunning();
      System.out.printf("Listening for messages on %s:\n", subscriptionName.toString());
      // Allow the subscriber to run for 30s unless an unrecoverable error occurs.
      subscriber.awaitTerminated(30, TimeUnit.MINUTES);
    } catch (TimeoutException timeoutException) {
      // Shut down the subscriber after 30s. Stop receiving messages.
      subscriber.stopAsync();
    }
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/java-pubsub API. label Jun 1, 2022
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Jun 2, 2022
@meredithslota meredithslota added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Jun 28, 2022
@hongalex hongalex added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/java-pubsub API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

6 participants