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

Handle backoff on HTTP 503 error when pushing repeatedly #1038

Merged
merged 6 commits into from
Sep 8, 2022

Conversation

Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Sep 7, 2022

Fix #1027.

This PR adds a separate helper to perform HTTP requests with a backoff strategy. Retries can be made on specific exceptions or specific status codes. By default, we mainly target Connection timeout and HTTP 503 Service Unavailable. It is a slight variation of the existing backoff implementation in _request_wrapper but separated so that we can unit tests and document it properly.

This PR adds backoff usage by default when pushing a LFS file to the Hub, which is the initial purpose of #1027. At the moment sleep times will increase as such: 1s, 2s, 4s, 8s, 8s, 8s...

I did not add the helper in the documentation since I'm not exactly sure yet if that's something we want to do at the moment. I think other HTTP-related helpers will come as user-agent handler (#1018) so maybe we can update documentation at that time. Docstring for http_backoff is already ready.

(for the record the excellent backoff package exists but is not used here to avoid an extra external dependency)

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 7, 2022

The documentation is not available anymore as the PR was closed or merged.

@codecov
Copy link

codecov bot commented Sep 8, 2022

Codecov Report

Merging #1038 (6536fa8) into main (8e5f219) will increase coverage by 0.18%.
The diff coverage is 97.56%.

@@            Coverage Diff             @@
##             main    #1038      +/-   ##
==========================================
+ Coverage   83.01%   83.20%   +0.18%     
==========================================
  Files          36       37       +1     
  Lines        3822     3846      +24     
==========================================
+ Hits         3173     3200      +27     
+ Misses        649      646       -3     
Impacted Files Coverage Δ
src/huggingface_hub/lfs.py 74.84% <66.66%> (ø)
src/huggingface_hub/file_download.py 85.79% <100.00%> (+0.34%) ⬆️
src/huggingface_hub/utils/__init__.py 100.00% <100.00%> (ø)
src/huggingface_hub/utils/_http.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@merveenoyan merveenoyan left a comment

Choose a reason for hiding this comment

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

Thanks a lot for tackling this!

src/huggingface_hub/utils/_http.py Show resolved Hide resolved
Copy link
Contributor

@SBrandeis SBrandeis left a comment

Choose a reason for hiding this comment

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

Very nice addition, thank you!

src/huggingface_hub/utils/_http.py Outdated Show resolved Hide resolved
src/huggingface_hub/utils/_http.py Outdated Show resolved Hide resolved
@Wauplin
Copy link
Contributor Author

Wauplin commented Sep 8, 2022

Thanks @SBrandeis and @merveenoyan for the review ! I'm merging once CI is happy :)

@Wauplin Wauplin merged commit 59873e7 into main Sep 8, 2022
@Wauplin Wauplin deleted the 1027-503-error-when-pushing-repeatedly-v2 branch September 8, 2022 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

503 Error when pushing repeatedly
4 participants