@@ -102,8 +102,7 @@ def __call__(self, func):
102
102
def func_with_timeout (* args , ** kwargs ):
103
103
"""Wrapped function that adds timeout."""
104
104
105
- remaining_timeout = self ._timeout
106
- if remaining_timeout is not None :
105
+ if self ._timeout is not None :
107
106
# All calculations are in seconds
108
107
now_timestamp = self ._clock ().timestamp ()
109
108
@@ -114,8 +113,19 @@ def func_with_timeout(*args, **kwargs):
114
113
now_timestamp = first_attempt_timestamp
115
114
116
115
time_since_first_attempt = now_timestamp - first_attempt_timestamp
117
- # Avoid setting negative timeout
118
- kwargs ["timeout" ] = max (0 , self ._timeout - time_since_first_attempt )
116
+ remaining_timeout = self ._timeout - time_since_first_attempt
117
+
118
+ # Although the `deadline` parameter in `google.api_core.retry.Retry`
119
+ # is deprecated, and should be treated the same as the `timeout`,
120
+ # it is still possible for the `deadline` argument in
121
+ # `google.api_core.retry.Retry` to be larger than the `timeout`.
122
+ # See https://github.com/googleapis/python-api-core/issues/654
123
+ # Only positive non-zero timeouts are supported.
124
+ # Revert back to the initial timeout for negative or 0 timeout values.
125
+ if remaining_timeout < 1 :
126
+ remaining_timeout = self ._timeout
127
+
128
+ kwargs ["timeout" ] = remaining_timeout
119
129
120
130
return func (* args , ** kwargs )
121
131
0 commit comments