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

[WIP] Handle errors #44

Closed
wants to merge 4 commits into from
Closed

Conversation

dpordomingo
Copy link
Contributor

@dpordomingo dpordomingo commented Oct 14, 2019

depends on #49 [implement MultiToken]
fix #3 [handle RateLimit errors]
fix #18 [handle Abuse errors]

TODO

  • Rebase over Multi token support #49 [implement MultiToken]
  • Integration tests testing: Retry + RateLimit (Could be added in a new PR, or also in this PR)

Changes grom ghsync

  • the retry policy is implemented by github.RetryTransport, not by github.RateLimitTransport

Also needed:

  • adf3a6b Enhance retryTransport:
    • retry also 500 errors
    • ensure it does not return errors but the ones from Transport.RoundTrip
    • log last error and the number of retries
  • ee869d8 Restore the Response&Request when read from Transport
    • Since the Request.Body and Response.Body are read from any transport.RoundTrip,
      it is needed to restore them before reusing it again;
      otherwise, their Body won't be readable from other nested Transport.

How does it work?

Trying to fetch an org with a GH token under an AbuseRateLimmit block, whose quota also expired:

  1. github.Downloader tries to get the data, but GH answers with n 403, AbuseRateLimmit,
  2. the error is intercepted by github.RateLimitTransport, and the lock is enabled for the time specified by the headers from the 403, AbuseRateLimmit; the error is bubbled up
  3. the error is captured by github.RetryTransport, and retried
  4. github.RateLimitTransport is locked, so it sleeps till the lock expires.
  5. once the lock expired, the request is processed. In a regular situation, an AbuseRateLimmit will disappear, but in this example, it appeared a RateLimmit for that same query which is intercepted again by github.RateLimitTransport, and the lock is enabled again for the time specified by the headers from the 200, StatusOk; the error is bubbled up
  6. the error is captured by github.RetryTransport, and retried
  7. github.RateLimitTransport is locked, so it sleeps till the lock expires.
  8. once the lock expired, the request is processed with no new limits.

trl3


  • I have updated the CHANGELOG file according to the conventions in keepachangelog.com
  • This PR contains changes that do not require a mention in the CHANGELOG file

@se7entyse7en
Copy link
Contributor

build on top of #49 [implement MultiToken]

Do you need this? they should be independent as you work at transport level. I mean if this is ready, I won't wait for #49.

Integration tests testing: Retry + RateLimit

AFAIS We already have unittests, let's open a different issue for integration tests, also maybe @kyrcha could take care of it.

I found (and fixed) some bugs caused when the Request/Response are read from a Transport, which cause that they're no longer available for other Transport in the chain.

AFAIR there was already a fix for this in ghsync.

@kyrcha
Copy link
Contributor

kyrcha commented Oct 15, 2019

I have reproduced (I think) all of the possible HTTP codes:

  • 200
  • 400
  • 401
  • 403
  • 502
  • 200 but with rate limit exceeded

for this issue #40 so tests will be added for such matters.

@dpordomingo dpordomingo force-pushed the handle-errors branch 4 times, most recently from c7d5921 to 00086cf Compare October 15, 2019 12:28
@dpordomingo dpordomingo marked this pull request as ready for review October 15, 2019 12:36
@dpordomingo
Copy link
Contributor Author

@se7entyse7en Yes, the rebase over #49 is needed; i.e. it's also causing the current conflict.
More details in my review for that PR
TL;DR you moved the Transport chain definition elsewhere, so I need to adapt this.

@se7entyse7en No, the issue about the ruined body was not added in ghsync because there was no Request.Body needed at all (because the query was built directly from the Request.URL.)
More details in 00086cf

@dpordomingo dpordomingo self-assigned this Oct 15, 2019
@dpordomingo dpordomingo requested review from a team October 15, 2019 12:44
@dpordomingo dpordomingo added bug Something isn't working enhancement New feature or request labels Oct 15, 2019
Its RoundTrip method will return ErrRateLimit or ErrAbuseRateLimit
if any of these API limits are reached.

Signed-off-by: David Pordomingo <[email protected]>
- document it
- ensure it does not return errors but the ones from Transport.RoundTrip
- retry also 500 errors
- log last error and the number of retries

Signed-off-by: David Pordomingo <[email protected]>
And enhance how the Transport are added

Signed-off-by: David Pordomingo <[email protected]>
Since the Request.Body and Response.Body are read from any transport.RoundTrip,
it is needed to restore them before reusing it again;
otherwise, the Request.Body or Response.Body won't be readable.

Signed-off-by: David Pordomingo <[email protected]>
@dpordomingo
Copy link
Contributor Author

dpordomingo commented Oct 15, 2019

.

@dpordomingo
Copy link
Contributor Author

I'll create a new PR from an upstream branch

Copy link
Contributor

@kyrcha kyrcha left a comment

Choose a reason for hiding this comment

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

I will wait for the new PR for the rest

out []string
}

func (l *LoggerMock) First() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

First or better Pop?

Comment on lines +8 to +9

"github.com/src-d/metadata-retrieval/utils"
Copy link
Contributor

Choose a reason for hiding this comment

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

According to previous reviews by @lwsanty the metadata-retrieval variables should be in the middle. I am guessing it is better if we build a linter for that matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Will do.

@dpordomingo dpordomingo mentioned this pull request Oct 15, 2019
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deal with abuse rate limits Handle rate limit errors
3 participants