diff --git a/crates/openwire-core/src/error.rs b/crates/openwire-core/src/error.rs index 4a2589e..d0fc276 100644 --- a/crates/openwire-core/src/error.rs +++ b/crates/openwire-core/src/error.rs @@ -21,7 +21,6 @@ pub enum WireErrorKind { Redirect, Body, Interceptor, - Capacity, Internal, } @@ -38,7 +37,6 @@ impl fmt::Display for WireErrorKind { Self::Redirect => "redirect", Self::Body => "body", Self::Interceptor => "interceptor", - Self::Capacity => "capacity", Self::Internal => "internal", }; @@ -355,8 +353,9 @@ impl WireError { Self::with_source(WireErrorKind::Interceptor, message, source) } + /// Creates an admission error for a full request queue. pub fn capacity(message: impl Into>) -> Self { - Self::new(WireErrorKind::Capacity, message) + Self::new(WireErrorKind::Internal, message).with_phase(FailurePhase::Admission) } pub fn internal(message: impl Into>, source: E) -> Self @@ -458,7 +457,6 @@ fn default_phase(kind: WireErrorKind) -> FailurePhase { WireErrorKind::Redirect => FailurePhase::Policy, WireErrorKind::Body => FailurePhase::ResponseBody, WireErrorKind::Interceptor => FailurePhase::Interceptor, - WireErrorKind::Capacity => FailurePhase::Admission, WireErrorKind::Internal => FailurePhase::Internal, } } @@ -517,8 +515,8 @@ mod tests { #[test] fn capacity_errors_map_to_admission_phase() { let error = WireError::capacity("request queue is full"); - assert_eq!(error.kind(), super::WireErrorKind::Capacity); + assert_eq!(error.kind(), super::WireErrorKind::Internal); assert_eq!(error.phase(), FailurePhase::Admission); - assert_eq!(error.to_string(), "capacity: request queue is full"); + assert_eq!(error.to_string(), "internal: request queue is full"); } } diff --git a/crates/openwire-core/tests/wire_error_kind_compat.rs b/crates/openwire-core/tests/wire_error_kind_compat.rs new file mode 100644 index 0000000..efcad85 --- /dev/null +++ b/crates/openwire-core/tests/wire_error_kind_compat.rs @@ -0,0 +1,23 @@ +use openwire_core::WireErrorKind; + +#[test] +fn downstream_can_still_match_all_v0_1_2_error_kinds() { + fn is_internal(kind: WireErrorKind) -> bool { + match kind { + WireErrorKind::Internal => true, + WireErrorKind::InvalidRequest + | WireErrorKind::Timeout + | WireErrorKind::Canceled + | WireErrorKind::Dns + | WireErrorKind::Connect + | WireErrorKind::Tls + | WireErrorKind::Protocol + | WireErrorKind::Redirect + | WireErrorKind::Body + | WireErrorKind::Interceptor => false, + } + } + + assert!(is_internal(WireErrorKind::Internal)); + assert!(!is_internal(WireErrorKind::Timeout)); +} diff --git a/crates/openwire/src/client.rs b/crates/openwire/src/client.rs index 15a9437..efdd425 100644 --- a/crates/openwire/src/client.rs +++ b/crates/openwire/src/client.rs @@ -526,8 +526,10 @@ impl ClientBuilder { } /// Caps how many calls may wait for a request-admission slot. Default is - /// `usize::MAX` (unbounded). A finite cap fails acquire with - /// [`WireErrorKind::Capacity`] before taking a running slot. + /// `usize::MAX` (unbounded). A full queue returns + /// [`WireErrorKind::Internal`](crate::WireErrorKind::Internal) with + /// [`FailurePhase::Admission`](openwire_core::FailurePhase::Admission) + /// before taking a running slot. pub fn max_queued_requests(mut self, max_queued: usize) -> Self { self.transport.max_queued_requests = max_queued; self diff --git a/crates/openwire/src/connection/scheduler.rs b/crates/openwire/src/connection/scheduler.rs index 475b77a..a108d9b 100644 --- a/crates/openwire/src/connection/scheduler.rs +++ b/crates/openwire/src/connection/scheduler.rs @@ -392,7 +392,7 @@ fn waiter_is_eligible(global: &GlobalState, id: usize, max_per_address: usize) - /// Only eligible queued requests (those that could take a slot now) block /// immediate admission. A waiter stuck on its per-address cap must not cause a -/// different host with spare capacity to take the queue-full `Capacity` path. +/// different host with spare capacity to fail request admission. fn queue_blocks_priority( global: &GlobalState, priority: RequestPriority, @@ -759,7 +759,7 @@ mod tests { .acquire(address.clone(), RequestPriority::Normal) .await .expect_err("queue is full"); - assert_eq!(error.kind(), openwire_core::WireErrorKind::Capacity); + assert_eq!(error.kind(), openwire_core::WireErrorKind::Internal); assert_eq!(error.phase(), openwire_core::FailurePhase::Admission); drop(first); diff --git a/crates/openwire/tests/scheduler_limits.rs b/crates/openwire/tests/scheduler_limits.rs index ce67434..efadc68 100644 --- a/crates/openwire/tests/scheduler_limits.rs +++ b/crates/openwire/tests/scheduler_limits.rs @@ -7,6 +7,7 @@ use std::time::Duration; use bytes::Bytes; use http::{Response, StatusCode}; use openwire::{Client, RequestPriority, WireErrorKind}; +use openwire_core::FailurePhase; use openwire_test::{ok_text, spawn_http1, RecordingEventListenerFactory, StaticDnsResolver}; use support::*; @@ -316,7 +317,9 @@ async fn max_queued_requests_fails_with_capacity_before_taking_a_slot() { ))) .await .expect_err("queue should be full"); - assert_eq!(error.kind(), WireErrorKind::Capacity); + assert_eq!(error.kind(), WireErrorKind::Internal); + assert_eq!(error.phase(), FailurePhase::Admission); + assert!(!error.request_committed()); drop(first); queued diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index bf51b2d..8191c9a 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -512,9 +512,9 @@ cargo test -p openwire --test live_network -- --ignored --test-threads=1 `max_connections_total`. Optional per-address caps default to unlimited. When a per-address cap is set, waiting on one host still does not consume a client-wide request slot. Queue precedence ignores waiters that cannot run - because their per-address cap is full, so a different host with spare - global and per-host capacity is not rejected with `Capacity` while the - queue holds only ineligible waiters. `max_queued_requests` fails - with `WireErrorKind::Capacity` before taking a running slot. Dropping a + because their per-address cap is full. A different host with spare global + and per-host capacity can proceed while the queue holds only ineligible + waiters. A full `max_queued_requests` queue returns `WireErrorKind::Internal` + in `FailurePhase::Admission` before taking a running slot. Dropping a queued or already-promoted acquire future must not leak running counts.