Skip to content

Commit

Permalink
fix: Add a really long timeout to PartitionLookupUtils (#965)
Browse files Browse the repository at this point in the history
This ensures that these functions are tolerant to possible bugs in the GRPC or GAPIC layers that can result in these futures being outstanding indefinitely.

Internal reference: b/208679723
  • Loading branch information
dpcollins-google committed Dec 7, 2021
1 parent 02cea6c commit 1c0678d
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.pubsublite;

import static com.google.cloud.pubsublite.internal.UncheckedApiPreconditions.checkState;
import static java.util.concurrent.TimeUnit.MINUTES;

import com.google.api.core.ApiFuture;
import com.google.api.gax.rpc.ApiException;
Expand All @@ -42,7 +43,7 @@ public static int numPartitions(TopicPath topic) throws ApiException {
public static int numPartitions(TopicPath topic, AdminClient client) throws ApiException {
ApiFuture<Long> partitionCountFuture = client.getTopicPartitionCount(topic);
try {
long numPartitions = partitionCountFuture.get();
long numPartitions = partitionCountFuture.get(1, MINUTES);
checkState(
numPartitions > 0, "Config has 0 or less partitions configured. This config is invalid.");
checkState(
Expand Down Expand Up @@ -76,7 +77,7 @@ public static int numPartitions(SubscriptionPath subscription, AdminClient clien
throws ApiException {
ApiFuture<Subscription> subscriptionFuture = client.getSubscription(subscription);
try {
return numPartitions(TopicPath.parse(subscriptionFuture.get().getTopic()), client);
return numPartitions(TopicPath.parse(subscriptionFuture.get(1, MINUTES).getTopic()), client);
} catch (Throwable t) {
throw ExtractStatus.toCanonical(t).underlying;
}
Expand Down

0 comments on commit 1c0678d

Please sign in to comment.