Skip to content

Commit bd6ef26

Browse files
fix: Stop using api_core default timeouts in publish since they are
broken
1 parent f648f65 commit bd6ef26

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

google/cloud/pubsub_v1/types.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from google.protobuf import timestamp_pb2
3636

3737
from google.api_core.protobuf_helpers import get_messages
38+
from google.api_core.timeout import ExponentialTimeout
3839

3940
from google.pubsub_v1.types import pubsub as pubsub_gapic_types
4041

@@ -191,7 +192,12 @@ class PublisherOptions(NamedTuple):
191192
"an instance of :class:`google.api_core.retry.Retry`."
192193
)
193194

194-
timeout: "OptionalTimeout" = gapic_v1.method.DEFAULT # use api_core default
195+
# Use ExponentialTimeout instead of api_core default because the default
196+
# value results in retries with zero deadline.
197+
# Refer https://github.com/googleapis/python-api-core/issues/654
198+
timeout: "OptionalTimeout" = ExponentialTimeout(
199+
initial=5, maximum=60, multiplier=1.3, deadline=600
200+
)
195201
(
196202
"Timeout settings for message publishing by the client. It should be "
197203
"compatible with :class:`~.pubsub_v1.types.TimeoutType`."

tests/unit/pubsub_v1/publisher/test_publisher_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from google.api_core import gapic_v1
3636
from google.api_core import retry as retries
3737
from google.api_core.gapic_v1.client_info import METRICS_METADATA_KEY
38+
from google.api_core.timeout import ExponentialTimeout
3839

3940
from google.cloud.pubsub_v1 import publisher
4041
from google.cloud.pubsub_v1 import types
@@ -660,7 +661,9 @@ def test_publish_new_batch_needed(creds):
660661
batch_done_callback=None,
661662
commit_when_full=True,
662663
commit_retry=gapic_v1.method.DEFAULT,
663-
commit_timeout=gapic_v1.method.DEFAULT,
664+
commit_timeout=ExponentialTimeout(
665+
initial=5, maximum=60, multiplier=1.3, deadline=600
666+
),
664667
)
665668
message_pb = gapic_types.PubsubMessage(data=b"foo", attributes={"bar": "baz"})
666669
wrapper = PublishMessageWrapper(message=message_pb)

0 commit comments

Comments
 (0)