Skip to content

Commit b49115e

Browse files
author
Tryn McCaffery
committed
fix(acp): retry transient relay query failures
Signed-off-by: Tryn McCaffery <[email protected]>
1 parent f3f7078 commit b49115e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

‎crates/buzz-acp/src/relay.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ pub struct RestClient {
240240

241241
/// Whether an HTTP status code is retriable (transient server/rate-limit errors).
242242
fn is_retriable_status(status: reqwest::StatusCode) -> bool {
243-
matches!(status.as_u16(), 429 | 502 | 503 | 504)
243+
let status = status.as_u16();
244+
status == 408 || status == 429 || (500..600).contains(&status)
244245
}
245246

246247
/// Base retry delays for transient HTTP failures: 500ms, 1s, 2s.
@@ -308,7 +309,7 @@ impl RestClient {
308309
}
309310

310311
/// Retry helper: executes `build_request` up to 4 times (1 attempt + 3 retries)
311-
/// on transient failures (429, 502, 503, 504, timeout, connect errors).
312+
/// on transient failures (408, 429, 5xx, timeout, connect errors).
312313
///
313314
/// NIP-98 auth events are re-signed on each attempt (they have a ±60s window).
314315
async fn request_with_retry<F, Fut>(
@@ -3995,6 +3996,23 @@ async fn wait_for_any_ok(
39953996
mod tests {
39963997
use super::*;
39973998

3999+
#[test]
4000+
fn rest_retry_statuses_cover_transient_relay_failures() {
4001+
for status in [408, 429, 500, 501, 502, 503, 504, 599] {
4002+
assert!(
4003+
is_retriable_status(reqwest::StatusCode::from_u16(status).unwrap()),
4004+
"HTTP {status} should be retried"
4005+
);
4006+
}
4007+
4008+
for status in [400, 401, 403, 404, 409, 422] {
4009+
assert!(
4010+
!is_retriable_status(reqwest::StatusCode::from_u16(status).unwrap()),
4011+
"HTTP {status} should fail without retry"
4012+
);
4013+
}
4014+
}
4015+
39984016
#[test]
39994017
fn relay_ws_to_http_plain() {
40004018
assert_eq!(

0 commit comments

Comments
 (0)