Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/openwire-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub enum WireErrorKind {
Redirect,
Body,
Interceptor,
Capacity,
Internal,
}

Expand All @@ -38,7 +37,6 @@ impl fmt::Display for WireErrorKind {
Self::Redirect => "redirect",
Self::Body => "body",
Self::Interceptor => "interceptor",
Self::Capacity => "capacity",
Self::Internal => "internal",
};

Expand Down Expand Up @@ -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<Cow<'static, str>>) -> Self {
Self::new(WireErrorKind::Capacity, message)
Self::new(WireErrorKind::Internal, message).with_phase(FailurePhase::Admission)
}

pub fn internal<E>(message: impl Into<Cow<'static, str>>, source: E) -> Self
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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");
}
}
23 changes: 23 additions & 0 deletions crates/openwire-core/tests/wire_error_kind_compat.rs
Original file line number Diff line number Diff line change
@@ -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));
}
6 changes: 4 additions & 2 deletions crates/openwire/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/openwire/src/connection/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion crates/openwire/tests/scheduler_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Loading