Skip to content

Commit 1c0678d

Browse files
fix: Add a really long timeout to PartitionLookupUtils (#965)
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
1 parent 02cea6c commit 1c0678d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

google-cloud-pubsublite/src/main/java/com/google/cloud/pubsublite/PartitionLookupUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.cloud.pubsublite;
1818

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

2122
import com.google.api.core.ApiFuture;
2223
import com.google.api.gax.rpc.ApiException;
@@ -42,7 +43,7 @@ public static int numPartitions(TopicPath topic) throws ApiException {
4243
public static int numPartitions(TopicPath topic, AdminClient client) throws ApiException {
4344
ApiFuture<Long> partitionCountFuture = client.getTopicPartitionCount(topic);
4445
try {
45-
long numPartitions = partitionCountFuture.get();
46+
long numPartitions = partitionCountFuture.get(1, MINUTES);
4647
checkState(
4748
numPartitions > 0, "Config has 0 or less partitions configured. This config is invalid.");
4849
checkState(
@@ -76,7 +77,7 @@ public static int numPartitions(SubscriptionPath subscription, AdminClient clien
7677
throws ApiException {
7778
ApiFuture<Subscription> subscriptionFuture = client.getSubscription(subscription);
7879
try {
79-
return numPartitions(TopicPath.parse(subscriptionFuture.get().getTopic()), client);
80+
return numPartitions(TopicPath.parse(subscriptionFuture.get(1, MINUTES).getTopic()), client);
8081
} catch (Throwable t) {
8182
throw ExtractStatus.toCanonical(t).underlying;
8283
}

0 commit comments

Comments
 (0)