Skip to content

feat: ADD rate-limiting functionality#1396

Open
mattclegg wants to merge 1 commit into
otto-de:mainfrom
mattclegg:rate-limiting
Open

feat: ADD rate-limiting functionality#1396
mattclegg wants to merge 1 commit into
otto-de:mainfrom
mattclegg:rate-limiting

Conversation

@mattclegg

Copy link
Copy Markdown

I was getting blocked when querying a large number of repositories (~2k).

Any feedback welcome.

Thanks

@boring-cyborg boring-cyborg Bot added the java Changes related to backend label Jul 1, 2026
@boring-cyborg

boring-cyborg Bot commented Jul 1, 2026

Copy link
Copy Markdown

Thanks for opening this pull request! Please check out our contributing guidelines!

@mattclegg mattclegg changed the title ADD rate-limiting functionality feat: ADD rate-limiting functionality Jul 1, 2026

private static boolean isRateLimited(HttpClientErrorException exception) {
final boolean rateLimitStatus =
FORBIDDEN.equals(exception.getStatusCode())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

429 is only rate limit status code, isn't it? FORBIDDEN is slightly different

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Unfortunately GitHub API will return either; https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2026-03-10#exceeding-the-rate-limit

The x-ratelimit-remaining header is used to determine if it's rate limit related.

}
log.warn("GitHub rate limit hit; waiting {}s until reset", waitFor.toSeconds());
try {
Thread.sleep(waitFor.toMillis());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it hang the complete system? also given waitUntilRateLimitResets will be called multiple times, multiple Threads will go on sleep mode. Ideally if the rate-limit got hit, then we should skip the remaining calls

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It wasn't hanging for me but just waiting until the limit was reset. waitFor is defined based on the value returned from the GitHub API.

For my use-case I wanted to ensure I had all the results and less concerned how long it took to wait for relevant rate limits to reset. If you think it might be useful to abort all requests once the limit is reached I can add that as an option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Changes related to backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants