Skip to content

Implement an abuse handler#289

Merged
kohsuke merged 1 commit into
hub4j:masterfrom
mmitche:abuse-handler
Aug 6, 2016
Merged

Implement an abuse handler#289
kohsuke merged 1 commit into
hub4j:masterfrom
mmitche:abuse-handler

Conversation

@mmitche
Copy link
Copy Markdown
Contributor

@mmitche mmitche commented Jul 21, 2016

If too many requests are made within X amount of time (not the traditional hourly rate limit), github may begin returning 403. Then we should wait for a bit to attempt to access the API again. In this case, we parse out the Retry-After field returned and sleep until that (it's usually 60 seconds)

Fixes #285

// Check to see whether we hit a 403, and the message indicates the
// abuse handler (occurs on too many concurrent requests)
if (responseCode == HttpURLConnection.HTTP_FORBIDDEN &&
errorString.contains("You have triggered an abuse detection mechanism.")) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kohsuke This is the only bit I'm not totally sure about. The best bit would be to just be able to check for 403, but I'm not sure whether 403 happens in more circumstances than just API abuse. There wasn't anything else in the header indicating abuse (though maybe I could just check for Retry-After)

Additionally, I imagine that there isn't a way to get a localized error string here, but if there was the check would be broken. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My 2 cents:
I'd just check for status code and retry-after, those are the ones that are documented.
The human readable hint/text isn't quite documented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, yeah I think you're right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

InputStream es = wrapStream(uc.getErrorStream());
try {
if (es!=null) {
String errorString = IOUtils.toString(es, "UTF-8");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Dead store to errorString in org.kohsuke.github.Requester.handleApiError(IOException) [org.kohsuke.github.Requester] At Requester.java:[line 579]

If too many requests are made within X amount of time (not the traditional hourly rate limit), github may begin returning 403.  Then we should wait for a bit to attempt to access the API again.  In this case, we parse out the Retry-After field returned and sleep until that (it's usually 60 seconds)
@mmitche
Copy link
Copy Markdown
Contributor Author

mmitche commented Jul 22, 2016

Fixed and moved some code around.

@kohsuke kohsuke merged commit 9f5a6ee into hub4j:master Aug 6, 2016
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.

3 participants