Skip to content

fix: assume ratelimit is not in effect if reset after is small amount #1585

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

Merged
merged 3 commits into from
Dec 2, 2023

Conversation

AstreaTSS
Copy link
Member

@AstreaTSS AstreaTSS commented Dec 2, 2023

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

Some endpoints give a "reset-after" ratelimit header that is so small as to not matter (Python overhead will be much slower anyways), but can cause issues with how interactions.py handles ratelimits. This PR checks for a very small "reset-after" and makes it 0 if that is the case.

Changes

  • If self.delta for a BucketLock is less than 0.005, make self.delta 0 and self.remaining 1.

Related Issues

Test Scenarios

Examples of a very small retry after can be found using a simple Curl request to /users/@me:

curl -i -X GET -H "Authorization: Bot YOUR_TOKEN" -H "Content-Type: application/json" https://discord.com/api/v10/users/@me
x-ratelimit-bucket: 78bb8553d9352a5a2f89f9def401287a
x-ratelimit-limit: 1000
x-ratelimit-remaining: 0
x-ratelimit-reset: 1701541977.957
x-ratelimit-reset-after: 0.001

Many other @me endpoints give a similar result.

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

@AstreaTSS AstreaTSS changed the title fix: assume ratelimit reset after is 0 if small amount fix: assume ratelimit is not in affect if reset after is small amount Dec 2, 2023
@AstreaTSS AstreaTSS changed the title fix: assume ratelimit is not in affect if reset after is small amount fix: assume ratelimit is not in effect if reset after is small amount Dec 2, 2023
@LordOfPolls LordOfPolls merged commit 1b811a2 into interactions-py:unstable Dec 2, 2023
@AstreaTSS AstreaTSS deleted the small-delta-fix branch December 4, 2023 20:41
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