-
Notifications
You must be signed in to change notification settings - Fork 90
fix: resolve the issue where rpc timeout of 0 is used when timeout expires #776
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
Changes from all commits
95cde20
b7ea26e
5b9a2e8
30ce320
03b27f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -102,8 +102,7 @@ def __call__(self, func): | |||
def func_with_timeout(*args, **kwargs): | ||||
"""Wrapped function that adds timeout.""" | ||||
|
||||
remaining_timeout = self._timeout | ||||
if remaining_timeout is not None: | ||||
if self._timeout is not None: | ||||
# All calculations are in seconds | ||||
now_timestamp = self._clock().timestamp() | ||||
|
||||
|
@@ -114,8 +113,19 @@ def func_with_timeout(*args, **kwargs): | |||
now_timestamp = first_attempt_timestamp | ||||
|
||||
time_since_first_attempt = now_timestamp - first_attempt_timestamp | ||||
# Avoid setting negative timeout | ||||
kwargs["timeout"] = max(0, self._timeout - time_since_first_attempt) | ||||
remaining_timeout = self._timeout - time_since_first_attempt | ||||
|
||||
# Although the `deadline` parameter in `google.api_core.retry.Retry` | ||||
# is deprecated, and should be treated the same as the `timeout`, | ||||
# it is still possible for the `deadline` argument in | ||||
# `google.api_core.retry.Retry` to be larger than the `timeout`. | ||||
Comment on lines
+120
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not explain how the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The deadline enters via
|
||||
# See https://github.com/googleapis/python-api-core/issues/654 | ||||
# Only positive non-zero timeouts are supported. | ||||
# Revert back to the initial timeout for negative or 0 timeout values. | ||||
if remaining_timeout < 1: | ||||
remaining_timeout = self._timeout | ||||
Comment on lines
+125
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this. This seems to be saying that if the next server-RPC timeout is ~0, we should reset it to be the GAPIC-surface level timeout, which seems wrong. I assume we're checking the GAPIC-surface level timeout elsewhere? Where? If we are indeed checking it elsewhere, clarify that here, and explain how the scenario leading up to this situation means it should be reset to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right @vchudnov-g , there is existing incorrect behavior and this simply avoids the specific failure of sending requests with an rpc timeout of 0, which fail immediately. More clarity is needed to document the current incorrect behavior and the workaround in this PR, as well as the recommended long term fix. As per offline discussion, we'll merge this as is and follow up with another PR to update the comments to provide more clarity. |
||||
|
||||
kwargs["timeout"] = remaining_timeout | ||||
|
||||
return func(*args, **kwargs) | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this
self._timeout
is meant to be treated as the total timeout and not a timeout for each retry.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some clean up that needs to happen as part of a longer term fix (Googlers see b/388247478) but for now I'd recommend to keep the definitions unchanged.