Skip to content

zulip: Optionally retry requests that hit RATE_LIMIT_HIT. - #924

Open
devnishantt wants to merge 1 commit into
zulip:mainfrom
devnishantt:fix/auto-retry-rate-limits
Open

devnishantt wants to merge 1 commit into
zulip:mainfrom
devnishantt:fix/auto-retry-rate-limits

Conversation

@devnishantt

Copy link
Copy Markdown
Collaborator

HTTP 429 currently bubbles up to every application. Tim asked for this
as an opt-in Client option so callers that cannot block keep the old
behavior.

When auto_retry_rate_limits=True, do_api_query sleeps for the
server's retry-after (JSON field, then Retry-After header) plus a small
jitter, then retries, up to 10 times. The cap and jitter avoid pinning
a client to the server's allowed rate.

Default is False.

Fixes #773.

Previous #908 implemented a simpler version of this and was closed
unreviewed.

How did you test this PR?
Unit tests in zulip/tests/test_rate_limit.py (7 passed): default off,
JSON retry-after, Retry-After header fallback, jitter, 10-retry cap.

Self-review checklist
  • Self-reviewed the changes for clarity and maintainability
    (variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

  • Explains differences from previous plans (e.g., issue description).
  • Highlights technical choices and bugs encountered.
  • Calls out remaining decisions and concerns.
  • Automated tests verify logic where appropriate.

Individual commits are ready for review (see commit discipline).

  • Each commit is a coherent idea.
  • Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

  • Visual appearance of the changes.
  • Responsiveness and internationalization.
  • Strings and tooltips.
  • End-to-end functionality of buttons, interactions and flows.
  • Corner cases, error conditions, and easily imagined bugs.

HTTP 429 currently bubbles up to every application. Tim asked for this
as an opt-in Client option so callers that cannot block keep the old
behavior.

When auto_retry_rate_limits=True, do_api_query sleeps for the server's
retry-after (JSON field, then Retry-After header) plus a small jitter,
then retries, up to 10 times. The cap and jitter avoid pinning a client
to the server's allowed rate.

Fixes zulip#773.

Signed-off-by: Nishant <nishanttgithub@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle RATE_LIMIT_HIT (Rate limit exceeded) errors

2 participants