Handle GitHub API rate limit errors appropriately#4299
Merged
Conversation
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
The bot has occasionally hit the GitHub API rate limit recently. When this happens, it keeps querying over and over regardless:
... which isn't what we're supposed to do:
https://docs.github.com/en/rest/using-the-rest-api/best-practices-for-using-the-rest-api#handle-rate-limit-errors-appropriately
Changes
Now if we get a rate limiting response from the GitHub API, we pause inflation for the time it requests and log that time span in the current mod's inflation error. This should allow the rate limit budget to recharge and keep us safer from being banned.
Known limitations
Due to how the logging works, the messages about pausing will only appear after the pause occurs. The Discord messages are sent by the Infra Python code, which receives them from AWS queue messages, which are batched in groups of 10. So if the third mod of a batch of 10 hits the limit, we'll pause for however long, then continue with mods 4–10 and finally send the message that alerts us to the pause.
I looked for a way around this, but did not find one. Maybe we can figure it out in the future.