GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: retry API calls with exponential backoff by andrewsg · Pull Request #287 · googleapis/python-storage

This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Conversation

@andrewsg

@andrewsg andrewsg commented Oct 2, 2020 •
edited by frankyn
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #108

Related: https://github.com/googleapis/google-cloud-python/issues/9298

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
andrewsg added 5 commits October 2, 2020 09:44
@andrewsg
unit tests pass
8d3ff6a
@andrewsg
_http tests
0c48398
@andrewsg
blacken
054710d
@andrewsg
lint
186362f
@andrewsg
notes
bbf10d7
@andrewsg
andrewsg requested a review from frankyn October 2, 2020 17:35
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 2, 2020
@frankyn frankyn added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 2, 2020
@frankyn
frankyn requested a review from crwilcox October 2, 2020 18:33
frankyn
frankyn suggested changes Oct 7, 2020
View reviewed changes

@frankyn frankyn left a comment

Copy link
Copy Markdown
Contributor

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.

Thank you for your patience, it took a bit more time than I expected to review the PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/hmac_key.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/bucket.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test_hmac_key.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/_http.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test__http.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrewsg

andrewsg commented Oct 8, 2020

Copy link
Copy Markdown
Contributor Author

@tritone FYI

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

crwilcox
crwilcox reviewed Oct 9, 2020
View reviewed changes
Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/unit/test__http.py
response.status_code = 200
data = b"brent-spiner"
response._content = data
http.request.return_value = response

@crwilcox crwilcox Oct 9, 2020

Copy link
Copy Markdown
Contributor

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.

this test is missing the comment the other tests have. There may be a way to refactor this also, but unsure if it is warranted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg Oct 9, 2020

Copy link
Copy Markdown
Contributor Author

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.

Which comment is missing?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
andrewsg added 5 commits October 9, 2020 11:15
@andrewsg
change etag behavior
741aff0
@andrewsg
Merge branch 'master' into retry
403afd4
@andrewsg
py2 compat
95293c1
@andrewsg
comments
73d37cf
@andrewsg
Support expanded error types for retry; retry ConnectionError; lint
46693d7
@andrewsg

andrewsg commented Oct 10, 2020

Copy link
Copy Markdown
Contributor Author

@crwilcox @frankyn PTAL. Changes include:

  • Retry predicate simplified; my testing suggests the google-api-core nuanced inspection of error messages is not needed for GCS.
  • Retry predicate now includes all HTTP error codes listed in retry design, except 408
    -- 408 is mysteriously missing from google-api-core exceptions and I have no way to test what happens if we actually get one (testbench was no help here)
  • Retry predicate now includes ConnectionError which encompasses failure to find host and broken connections of all types. LMK if we need to narrow it down; we have fairly rich and detailed info on the specific ConnectionError subtype which we can use here.

Responded to all other comments as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andrewsg added 3 commits October 12, 2020 09:24
@andrewsg
py2 compat
7052b12
@andrewsg
add support for 408 exceptions
5f0f473
@andrewsg
lint
8ba68c4
frankyn
frankyn suggested changes Oct 15, 2020
View reviewed changes

@frankyn frankyn left a comment

Copy link
Copy Markdown
Contributor

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.

Generally LGTM, clean design with minimal impact on the code base!

Have documentation comment requests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/retry.py
exceptions.BadGateway, # 502
exceptions.ServiceUnavailable, # 503
exceptions.GatewayTimeout, # 504
requests.ConnectionError,

@frankyn frankyn Oct 15, 2020

Copy link
Copy Markdown
Contributor

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.

@tritone this is a change in what we discussed around retrying ConnectionErrors in general. Discussed this with @andrewsg w.r.t retrying unable to connect errors and for now implementation is moving forward with this solution until it's baked into the api_core libraries. Rationale, there's a default timeout enabled that would timeout the retry compared to Golang which does not.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tritone tritone Oct 15, 2020

Copy link
Copy Markdown
Contributor

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.

Got it, this seems fine to me re: the fact that there is a default timeout in python. So the idea is that down the road, we can add an error in api_core which catches "connection reset by peer" more specifically?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Oct 15, 2020

Copy link
Copy Markdown
Contributor

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.

that's correct, because right now requests.ConnectionError is tied to a specific implementation, e.g. requests and should be wrapped by api_core / cloud_core for it to be used generally outside of just the GCS library.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg Oct 15, 2020

Copy link
Copy Markdown
Contributor Author

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'm not totally convinced that retrying for a little while by default if there is an interruption due to network outage is not the right thing to do anyways, but yes, the idea is that instead of tapping into requests here we would have a custom api_core exception like we do with other errors.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google/cloud/storage/retry.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrewsg andrewsg removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Oct 15, 2020
@andrewsg
documentation
ffa6527
@andrewsg

andrewsg commented Oct 15, 2020

Copy link
Copy Markdown
Contributor Author

@frankyn Added documentation as requested, PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tritone
tritone reviewed Oct 15, 2020
View reviewed changes

@tritone tritone left a comment

Copy link
Copy Markdown
Contributor

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.

Couple small comments, generally looks really good!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/retry.py
exceptions.BadGateway, # 502
exceptions.ServiceUnavailable, # 503
exceptions.GatewayTimeout, # 504
requests.ConnectionError,

@tritone tritone Oct 15, 2020

Copy link
Copy Markdown
Contributor

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.

Got it, this seems fine to me re: the fact that there is a default timeout in python. So the idea is that down the road, we can add an error in api_core which catches "connection reset by peer" more specifically?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google/cloud/storage/retry.py
To modify the default retry behavior, call a ``with_XXX`` method
on ``DEFAULT_RETRY``. For example, to change the deadline to 30 seconds,
pass ``retry=DEFAULT_RETRY.with_deadline(30)``. See google-api-core reference
(https://googleapis.dev/python/google-api-core/latest/retry.html) for details.

@tritone tritone Oct 15, 2020

Copy link
Copy Markdown
Contributor

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.

Would it be worth having a short sample snippet here rather than explaining and inlining? Might make it easier to understand what's necessary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewsg andrewsg Oct 15, 2020

Copy link
Copy Markdown
Contributor Author

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 decided against this since a useful snippet here would have to show how to actually inject the modified retry via user code, and that feature is out of scope for this PR (will require changing the signature of every method in the library).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@andrewsg andrewsg added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 15, 2020
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 15, 2020
@andrewsg
Merge branch 'master' into retry
1d46d1c
frankyn
frankyn approved these changes Oct 15, 2020
View reviewed changes
@andrewsg
andrewsg merged commit fbe5d9c into master Oct 16, 2020
@andrewsg
andrewsg deleted the retry branch October 16, 2020 19:21
@NoahDragon

NoahDragon commented Nov 9, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Just wonder if the blob.update() also has the retry logic with this feature. Is there any way to specify the retry number?

Update: followed the API core doc, using DEFAULT_RETRY as decorator seems works. But how can I confirm if the retry happened?

Update: there is a fix on this PR #340

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@andrewsg @cojenco
feat: retry API calls with exponential backoff (googleapis#287)
45cebae
Retries errors for idempotent API calls by default. Some API calls are conditionally idempotent (only idempotent if etag, generation, if_generation_match, if_metageneration_match are specified); in those cases, retries are also conditional on the inclusion of that data in the call.
cojenco pushed a commit to cojenco/python-storage that referenced this pull request Oct 13, 2021
@andrewsg @cojenco
feat: retry API calls with exponential backoff (googleapis#287)
573d039
Retries errors for idempotent API calls by default. Some API calls are conditionally idempotent (only idempotent if etag, generation, if_generation_match, if_metageneration_match are specified); in those cases, retries are also conditional on the inclusion of that data in the call.
@release-please release-please Bot mentioned this pull request Jan 12, 2022
chore(main): release 3.0.0 #688
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

3 more reviewers
@crwilcox crwilcox crwilcox left review comments
@tritone tritone tritone left review comments
@frankyn frankyn frankyn approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Add retry (exponential backoff) for storage api functions

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@andrewsg @NoahDragon @crwilcox @frankyn @tritone @yoshi-kokoro
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.