pycontribs / jira

Python Jira library. Development chat available on https://matrix.to/#/#pycontribs:matrix.org
https://jira.readthedocs.io
BSD 2-Clause "Simplified" License
1.95k stars 863 forks source link

Improve handling of Jira's retry-after handling #1825

Closed matthias-bach-by closed 6 months ago

matthias-bach-by commented 7 months ago

As reported in #1805, while 3.6.0 brought a beneficial change in evaluating Jira's retry-after header, in some scenarios it actually degraded the success rate of requests when hitting rate-limits due to two issues:

  1. Jira intends the retry-after header to be a minimum backoff but the code treats it as a maximum backoff, and
  2. Jira sometimes sends a retry-after value of 0 seconds which the existing code implicitly treated as a failed request.

To address this, this PR changes the back-off behaviour to treat the retry-after time as a minimum backoff, at least as long as our maximum back-off time does allow this, and clips the retry-after header, if specified, to a minimum of one second.

I have extended the existing tests for the retry logic to assert this behaviour. If you would prefer a separate set of tests or see other changes to the approach, let me know and I'll adjust the PR.

matthias-bach-by commented 7 months ago

The cloud tests are failing in set-up and this seems to be a wider issue unrelated to my changes as I am also seeing that on other PRs. Happy to rebase once that is fixed on main.

adehad commented 6 months ago

Thanks for the excellent PR and sorry for the delay in getting in merged and released!