Skip to content

Commit 46af494

Browse files
committed
Only retry on 403 FORBIDDEN or 429 TOO_MANY_REQUESTS
GitHub's docs clearly state that it will only respond with 403 or 429 if you exceed the rate limit. https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#exceeding-the-rate-limit The current logic was triggering a retry for all non-success responses. In some situations (like expected 404 responses), this was causing triagebot to send 3 extra needless requests.
1 parent 2a42a20 commit 46af494

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/github.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ impl GithubClient {
5151
const REMAINING: &str = "X-RateLimit-Remaining";
5252
const RESET: &str = "X-RateLimit-Reset";
5353

54-
if resp.status().is_success() {
54+
if !matches!(
55+
resp.status(),
56+
StatusCode::FORBIDDEN | StatusCode::TOO_MANY_REQUESTS
57+
) {
5558
return None;
5659
}
5760

@@ -60,12 +63,6 @@ impl GithubClient {
6063
return None;
6164
}
6265

63-
// Weird github api behavior. It asks us to retry but also has a remaining count above 1
64-
// Try again immediately and hope for the best...
65-
if headers[REMAINING] != "0" {
66-
return Some(Duration::from_secs(0));
67-
}
68-
6966
let reset_time = headers[RESET].to_str().unwrap().parse::<u64>().unwrap();
7067
Some(Duration::from_secs(Self::calc_sleep(reset_time) + 10))
7168
}

0 commit comments

Comments
 (0)