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

feat: support HTTP 429 with Retry-After #194

Merged
merged 7 commits into from
Mar 6, 2023
Merged

feat: support HTTP 429 with Retry-After #194

merged 7 commits into from
Mar 6, 2023

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Mar 3, 2023

This closes #188.

  • Moved all - I think - logic related to errors to errors.go. I also added some simply sanity tests for this new error as it is its own custom type to support the RetryAfter field.
  • Added gateway.ErrTooManyRequests. Returning an error of this type will make the gateway return 429. If the field RetryAfter above 0, it will set the Retry-After header. Also added a more "e2e" test for this, albeit arguable unnecessary since I added tests for webError.

@hacdias hacdias self-assigned this Mar 3, 2023
@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Merging #194 (1086d9d) into main (00e0249) will increase coverage by 0.25%.
The diff coverage is 77.06%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #194      +/-   ##
==========================================
+ Coverage   29.75%   30.01%   +0.25%     
==========================================
  Files         100      101       +1     
  Lines       11268    11312      +44     
==========================================
+ Hits         3353     3395      +42     
- Misses       7547     7549       +2     
  Partials      368      368              
Impacted Files Coverage Δ
bitswap/client/internal/session/session.go 0.00% <0.00%> (ø)
...tswap/client/internal/session/sessionwantsender.go 0.00% <0.00%> (ø)
bitswap/message/pb/cid.go 50.00% <0.00%> (ø)
bitswap/wantlist/forward.go 0.00% <ø> (ø)
files/serialfile.go 66.32% <0.00%> (ø)
gateway/handler.go 64.23% <50.00%> (-0.80%) ⬇️
gateway/errors.go 84.94% <84.94%> (ø)
files/multifilereader.go 81.81% <100.00%> (-0.21%) ⬇️

@hacdias hacdias marked this pull request as ready for review March 3, 2023 10:56
@hacdias hacdias requested a review from lidel as a code owner March 3, 2023 10:56
gateway/errors.go Outdated Show resolved Hide resolved
gateway/errors.go Outdated Show resolved Hide resolved
@hacdias hacdias requested a review from lidel March 3, 2023 14:26
@hacdias hacdias requested a review from a team as a code owner March 3, 2023 15:12
Makes it possible to pass RetryAfter as a hint for any error,
not just 429
First stab at making things more generic
lidel added a commit to ipfs-inactive/bifrost-gateway that referenced this pull request Mar 6, 2023
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

💭 something I've realized during this review is that Retry-After is not limited to 429 Too Many Requests, which is used when user is sending too many requests. There are cases where Retry-After is returned with 503 Service Unavailable (when it is not specific to user or their IP, could be global outage).

Pushed two commits which replace all standalone errors with generic wrappers: ErrorResponse and ErrorRetryAfter, and attempted to wire that up in ipfs-inactive/bifrost-gateway#56 – existing tests pass and does the trick, but I feel we could simplify things somehow.

@hacdias lmk if you have any idea how to make this better (if not, we can merge as-is, to unblock Retry-After, and refine later)

@lidel lidel changed the title feat: add ErrTooManyRequests to support Retry-After and 429 feat: support HTTP 429 with Retry-After Mar 6, 2023
@hacdias hacdias merged commit 15f2131 into main Mar 6, 2023
@hacdias hacdias deleted the issues/188 branch March 6, 2023 08:44
@hacdias
Copy link
Member Author

hacdias commented Mar 6, 2023

@lidel I think the way you rewrote it is a good idea. I'm not sure how we could simplify this now, but maybe later we will figure something out. Merged for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.

gateway: add 429 handling and ErrGatewayRetryAfter
2 participants