Skip to content

Commit a9e01d7

Browse files
committed
fix(guard): preserve actor ready timeout retries
1 parent 9be1845 commit a9e01d7

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

engine/packages/guard-core/src/utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ pub(crate) fn should_retry_request(res: &Result<Response<ResponseBody>>) -> bool
226226
}
227227
}
228228

229-
// Determine if a response should trigger a retry: 503 + x-rivet-error
229+
// Determine if a response should trigger a retry. Guard-specific actor startup
230+
// failures, including guard.actor_ready_timeout, are signaled as 503 with
231+
// x-rivet-error and should be retried against a freshly resolved target.
230232
pub(crate) fn should_retry_request_inner(status: StatusCode, headers: &hyper::HeaderMap) -> bool {
231233
status == StatusCode::SERVICE_UNAVAILABLE && headers.contains_key(X_RIVET_ERROR)
232234
}
@@ -294,3 +296,7 @@ pub(crate) fn to_hyper_close(frame: Option<CloseFrame>) -> hyper_tungstenite::tu
294296
))
295297
}
296298
}
299+
300+
#[cfg(test)]
301+
#[path = "utils/tests.rs"]
302+
mod tests;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use hyper::header::HeaderValue;
2+
3+
use super::*;
4+
5+
#[test]
6+
fn retries_guard_actor_ready_timeout_response() {
7+
let mut headers = hyper::HeaderMap::new();
8+
headers.insert(
9+
X_RIVET_ERROR,
10+
HeaderValue::from_static("guard.actor_ready_timeout"),
11+
);
12+
13+
assert!(should_retry_request_inner(
14+
StatusCode::SERVICE_UNAVAILABLE,
15+
&headers,
16+
));
17+
}
18+
19+
#[test]
20+
fn skips_service_unavailable_without_rivet_error_header() {
21+
let headers = hyper::HeaderMap::new();
22+
23+
assert!(!should_retry_request_inner(
24+
StatusCode::SERVICE_UNAVAILABLE,
25+
&headers,
26+
));
27+
}
28+
29+
#[test]
30+
fn skips_non_service_unavailable_with_rivet_error_header() {
31+
let mut headers = hyper::HeaderMap::new();
32+
headers.insert(X_RIVET_ERROR, HeaderValue::from_static("guard.no_route"));
33+
34+
assert!(!should_retry_request_inner(StatusCode::NOT_FOUND, &headers));
35+
}

0 commit comments

Comments
 (0)