Skip to content
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

fix: check if retry is allowed after retry wait calculation #258

Merged
merged 5 commits into from Aug 30, 2021

Conversation

cojenco
Copy link
Contributor

@cojenco cojenco commented Aug 25, 2021

_helpers.wait_and_retry() handles many of the retry calls in the library and utilizes retry_allowed(). Given the logic in retry_allowed(), the check should happen after the num_retries and total_sleep incrementation.

For example, if RetryStrategy.max_retries = 0, the check should prevent any additional retry attempts. With the previous logic, 1 retry call would be made.

If RetryStrategy.max_cumulative_retry = 100, the check should prevent another retry that will cause the total sleep time to exceed 100. Moving the order of the retry_allowed check resolves this.

Fixes #256

@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/google-resumable-media-python API. label Aug 25, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Aug 25, 2021
@cojenco cojenco marked this pull request as ready for review August 25, 2021 21:07
@cojenco cojenco requested a review from a team as a code owner August 25, 2021 21:07
@cojenco cojenco requested a review from andrewsg August 25, 2021 21:07
Copy link
Contributor

@andrewsg andrewsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I'm concerned at why there aren't more tests we have to change to reflect this. Do we not have any tests that test the case where retry strategy max_retries is used, instead of the timer-based settings? Do we need to add one, as a regression test?


# Check if (another) retry is allowed. If retries are exhausted and
# no acceptable response was received, raise the retriable error.
if not retry_strategy.retry_allowed(total_sleep, num_retries):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for retry_strategy.retry_allowed() says that the num_retries is supposed to be the number of retries used so far. After thinking about it, I agree with your changes here and think that docstring is wrong. We should modify the docstring to reflect this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewsg I've updated the docstring and added another test case. PTAL, thanks!

@cojenco cojenco requested a review from andrewsg August 30, 2021 17:17
@cojenco cojenco merged commit 00ccf71 into googleapis:main Aug 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/google-resumable-media-python API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retries are not checked correctly in the helper method
3 participants