From 5eb92933ae059afde9b78674d988ba9cf964ba86 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 10 Nov 2026 16:50:17 +0000 Subject: [PATCH 01/13] chore(deps): [#2776] require axum-server 0.9 Co-Authored-By: Claude Sonnet 5.5 --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- packages/axum-health-check-api-server/Cargo.toml | 2 +- packages/axum-http-server/Cargo.toml | 2 +- packages/axum-rest-api-server/Cargo.toml | 2 +- packages/axum-server/Cargo.toml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68692b044a..fa268b3f1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4458,7 +4458,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom 0.3.4", "once_cell", "rustix", "windows-sys 0.61.2", @@ -5925,7 +5925,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0d77835695..f385f4e88d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,7 +84,7 @@ rust-version = "1.88" [dependencies] anyhow = "1" -axum-server = { version = "0", features = [ "tls-rustls-no-provider" ] } +axum-server = { version = "0.9", features = [ "tls-rustls-no-provider" ] } base64 = "0.23.1" torrust-tracker-http-core = { version = "0.1.0", path = "packages/http-core" } torrust-tracker-core = { version = "0.1.0", path = "packages/tracker-core" } diff --git a/packages/axum-health-check-api-server/Cargo.toml b/packages/axum-health-check-api-server/Cargo.toml index 70980f04b2..fd974c6777 100644 --- a/packages/axum-health-check-api-server/Cargo.toml +++ b/packages/axum-health-check-api-server/Cargo.toml @@ -24,7 +24,7 @@ testing = [ "dep:torrust-tracker-configuration" ] [dependencies] axum = { version = "0", features = [ "macros" ] } -axum-server = { version = "0", features = [ "tls-rustls-no-provider" ] } +axum-server = { version = "0.9", features = [ "tls-rustls-no-provider" ] } futures = "0" hyper = "1" serde = { version = "1", features = [ "derive" ] } diff --git a/packages/axum-http-server/Cargo.toml b/packages/axum-http-server/Cargo.toml index 63ba997ca7..61dddbbef0 100644 --- a/packages/axum-http-server/Cargo.toml +++ b/packages/axum-http-server/Cargo.toml @@ -25,7 +25,7 @@ testing = [ "dep:torrust-clock", "dep:torrust-info-hash", "dep:torrust-tracker-s [dependencies] axum = { version = "0", features = [ "macros" ] } axum-client-ip = "1" -axum-server = { version = "0", features = [ "tls-rustls-no-provider" ] } +axum-server = { version = "0.9", features = [ "tls-rustls-no-provider" ] } torrust-tracker-http-core = { version = "0.1.0", path = "../http-core" } torrust-tracker-http-protocol = { version = "0.1.0", path = "../http-protocol" } torrust-info-hash = { version = "=0.2.0", optional = true } diff --git a/packages/axum-rest-api-server/Cargo.toml b/packages/axum-rest-api-server/Cargo.toml index d291685afe..a66dcdabf8 100644 --- a/packages/axum-rest-api-server/Cargo.toml +++ b/packages/axum-rest-api-server/Cargo.toml @@ -33,7 +33,7 @@ testing = [ [dependencies] axum = { version = "0", features = [ "macros" ] } axum-extra = { version = "0", features = [ "query" ] } -axum-server = { version = "0", features = [ "tls-rustls-no-provider" ] } +axum-server = { version = "0.9", features = [ "tls-rustls-no-provider" ] } torrust-tracker-http-core = { version = "0.1.0", path = "../http-core", optional = true } torrust-info-hash = "=0.2.0" torrust-tracker-core = { version = "0.1.0", path = "../tracker-core", optional = true } diff --git a/packages/axum-server/Cargo.toml b/packages/axum-server/Cargo.toml index 66490959b0..aac5a10a72 100644 --- a/packages/axum-server/Cargo.toml +++ b/packages/axum-server/Cargo.toml @@ -17,7 +17,7 @@ version = "0.1.0" workspace = true [dependencies] -axum-server = { version = "0", features = [ "tls-rustls-no-provider" ] } +axum-server = { version = "0.9", features = [ "tls-rustls-no-provider" ] } camino = { version = "1", features = [ "serde", "serde1" ] } futures-util = "0" http-body = "1" From 7d4645b8ddac95761ba36c2eb385f1612083c552 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 10 Nov 2026 16:57:12 +0000 Subject: [PATCH 02/13] test(axum-server): [#2776] add red idle-connection regression tests Introduce injectable Timeouts for the shared constructors (first_request declared but not yet applied) and tests that fail on that behaviour: silent plaintext and TLS connections. Stalled handshake and post-response idle (HTTP/1 and HTTP/2) are bounded already. Co-Authored-By: Claude Sonnet 5.5 --- Cargo.lock | 2 + .../evidence/red-run.txt | 10 + packages/axum-server/Cargo.toml | 2 + .../axum-server/src/custom_axum_server.rs | 71 +++- .../fixtures/https-health-check-cert.pem | 20 ++ .../tests/fixtures/https-health-check-key.pem | 28 ++ .../axum-server/tests/idle_connections.rs | 317 ++++++++++++++++++ project-words.txt | 2 + 8 files changed, 440 insertions(+), 12 deletions(-) create mode 100644 docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt create mode 100644 packages/axum-server/tests/fixtures/https-health-check-cert.pem create mode 100644 packages/axum-server/tests/fixtures/https-health-check-key.pem create mode 100644 packages/axum-server/tests/idle_connections.rs diff --git a/Cargo.lock b/Cargo.lock index fa268b3f1b..6addb71f18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5078,8 +5078,10 @@ dependencies = [ "hyper", "hyper-util", "pin-project-lite", + "rustls", "thiserror 2.0.21", "tokio", + "tokio-rustls", "tokio-util", "torrust-located-error", "torrust-server-lib", diff --git a/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt new file mode 100644 index 0000000000..1dc91ebf7f --- /dev/null +++ b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt @@ -0,0 +1,10 @@ +test it_should_answer_a_request_sent_within_the_first_request_timeout ... ok +test it_should_close_an_idle_http1_connection_after_a_response_over_plaintext ... ok +test it_should_close_a_tls_connection_that_never_sends_handshake_bytes ... ok +test it_should_close_a_tls_connection_that_sends_one_handshake_byte_and_stalls ... ok +test it_should_close_an_idle_http1_connection_after_a_response_over_tls ... ok +test it_should_close_an_idle_http2_connection_after_a_response_over_plaintext ... ok +test it_should_close_an_idle_http2_connection_after_a_response_over_tls ... ok +test it_should_close_a_plaintext_connection_that_sends_nothing ... FAILED +test it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing ... FAILED +test result: FAILED. 7 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 3.00s diff --git a/packages/axum-server/Cargo.toml b/packages/axum-server/Cargo.toml index aac5a10a72..81b7e482bd 100644 --- a/packages/axum-server/Cargo.toml +++ b/packages/axum-server/Cargo.toml @@ -35,4 +35,6 @@ tracing = "0" [dev-dependencies] axum = "0.8.9" +rustls = { version = "0.23", default-features = false, features = [ "ring" ] } +tokio-rustls = { version = "0.26", default-features = false, features = [ "ring" ] } tokio = { version = "1", features = [ "io-util", "test-util" ] } diff --git a/packages/axum-server/src/custom_axum_server.rs b/packages/axum-server/src/custom_axum_server.rs index b2313459dc..85aacfd271 100644 --- a/packages/axum-server/src/custom_axum_server.rs +++ b/packages/axum-server/src/custom_axum_server.rs @@ -39,38 +39,85 @@ use tower::Service; type RustlsServerResult = Result, std::io::Error>; type ServerResult = Result, std::io::Error>; -const HTTP1_HEADER_READ_TIMEOUT: Duration = Duration::from_secs(5); -const HTTP2_KEEP_ALIVE_TIMEOUT: Duration = Duration::from_secs(5); -const HTTP2_KEEP_ALIVE_INTERVAL: Duration = Duration::from_secs(5); +/// Connection timeouts applied to every Axum listener. +/// +/// The defaults are the values the tracker has always used for plaintext +/// listeners (5 s), plus the `axum-server` default TLS handshake bound (10 s). +/// The fields are public so tests can inject short values. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Timeouts { + /// Time a new connection has to send a complete first request. + pub first_request: Duration, + /// Hyper HTTP/1 header read timeout. + pub http1_header_read: Duration, + /// Hyper HTTP/2 keep-alive timeout (wait for a ping acknowledgement). + pub http2_keep_alive_timeout: Duration, + /// Hyper HTTP/2 keep-alive interval (time between pings). + pub http2_keep_alive_interval: Duration, + /// Time a TLS client has to complete the handshake. + pub tls_handshake: Duration, +} + +impl Default for Timeouts { + fn default() -> Self { + Self { + first_request: Duration::from_secs(5), + http1_header_read: Duration::from_secs(5), + http2_keep_alive_timeout: Duration::from_secs(5), + http2_keep_alive_interval: Duration::from_secs(5), + tls_handshake: Duration::from_secs(10), + } + } +} -/// Creates an Axum server from a TCP listener with configured timeouts. +/// Creates an Axum server from a TCP listener with the default timeouts. /// /// # Errors /// /// Returns an error if the server cannot be created from the TCP socket. pub fn from_tcp_with_timeouts(socket: TcpListener) -> ServerResult { - axum_server::from_tcp(socket).map(add_timeouts) + from_tcp_with(socket, Timeouts::default()) +} + +/// Creates an Axum server from a TCP listener with the given timeouts. +/// +/// # Errors +/// +/// Returns an error if the server cannot be created from the TCP socket. +pub fn from_tcp_with(socket: TcpListener, timeouts: Timeouts) -> ServerResult { + axum_server::from_tcp(socket).map(|server| add_timeouts(server, &timeouts)) } -/// Creates an Axum server from a TCP listener with TLS and configured timeouts. +/// Creates an Axum server from a TCP listener with TLS and the default timeouts. /// /// # Errors /// /// Returns an error if the server cannot be created from the TCP socket or if TLS configuration fails. pub fn from_tcp_rustls_with_timeouts(socket: TcpListener, tls: RustlsConfig) -> RustlsServerResult { - axum_server::from_tcp_rustls(socket, tls).map(add_timeouts) + from_tcp_rustls_with(socket, tls, Timeouts::default()) +} + +/// Creates an Axum server from a TCP listener with TLS and the given timeouts. +/// +/// # Errors +/// +/// Returns an error if the server cannot be created from the TCP socket or if TLS configuration fails. +pub fn from_tcp_rustls_with(socket: TcpListener, tls: RustlsConfig, timeouts: Timeouts) -> RustlsServerResult { + let acceptor = RustlsAcceptor::new(tls).handshake_timeout(timeouts.tls_handshake); + + axum_server::from_tcp(socket).map(|server| add_timeouts(server.acceptor(acceptor), &timeouts)) } -fn add_timeouts(mut server: Server) -> Server { +fn add_timeouts(mut server: Server, timeouts: &Timeouts) -> Server { server.http_builder().http1().timer(TokioTimer::new()); server.http_builder().http2().timer(TokioTimer::new()); - server.http_builder().http1().header_read_timeout(HTTP1_HEADER_READ_TIMEOUT); + server.http_builder().http1().header_read_timeout(timeouts.http1_header_read); server .http_builder() .http2() - .keep_alive_timeout(HTTP2_KEEP_ALIVE_TIMEOUT) - .keep_alive_interval(HTTP2_KEEP_ALIVE_INTERVAL); + .keep_alive_timeout(timeouts.http2_keep_alive_timeout) + .keep_alive_interval(timeouts.http2_keep_alive_interval); server } @@ -86,7 +133,7 @@ impl Accept for TimeoutAcceptor { fn accept(&self, stream: I, service: S) -> Self::Future { let (tx, rx) = mpsc::unbounded_channel(); - let stream = TimeoutStream::new(stream, HTTP1_HEADER_READ_TIMEOUT, rx); + let stream = TimeoutStream::new(stream, Timeouts::default().http1_header_read, rx); let service = TimeoutService::new(service, tx); std::future::ready(Ok((stream, service))) diff --git a/packages/axum-server/tests/fixtures/https-health-check-cert.pem b/packages/axum-server/tests/fixtures/https-health-check-cert.pem new file mode 100644 index 0000000000..c71ea19243 --- /dev/null +++ b/packages/axum-server/tests/fixtures/https-health-check-cert.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDPjCCAiagAwIBAgIUEukNWnLyuxpFxG5ZyorWu05aSfcwDQYJKoZIhvcNAQEL +BQAwFDESMBAGA1UEAwwJMTI3LjAuMC4xMB4XDTI2MDgyNDE4MzkwMVoXDTM2MDgy +MTE4MzkwMVowFDESMBAGA1UEAwwJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEF +AAOCAQ8AMIIBCgKCAQEA1AucnH+4mqRP9D1Frd04+tG7iCSQQxFSV4YvJpWQ54aN +Cfu3WWB9iLLh3th2uAA1jSmIjH6k0krG6PXnxbPMryJekt1B8SaYS/Nl0IUXLnA+ +EJWCOI66C6Pj646iN1gm6X+kVvx/H3DGAW7akaZ/zza7JciQ0fgDpROJRoF32UQS +Cj0ExvgV8Zixm62XtpwsrxC+MUvnezCARPYo5rcIAPdLQcMYdY/ozenJorhAhiZM +4jLpBlSQaEZ5qwBuLoEZzzwCvKWHafNxx7RRQfq2Y1lys/x2N1ayRPVihw5/0hWQ +3lKXIOsVB0ZrHjFoz6Ebbf6gwsCVPPMHE1/u1o8mtwIDAQABo4GHMIGEMA8GA1Ud +EQQIMAaHBH8AAAEwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBaAwEwYDVR0l +BAwwCgYIKwYBBQUHAwEwHQYDVR0OBBYEFLcsjXhBKUFINATA9q6N7JpZbK7VMB8G +A1UdIwQYMBaAFLcsjXhBKUFINATA9q6N7JpZbK7VMA0GCSqGSIb3DQEBCwUAA4IB +AQAktz7HmCNqUMFiAVT6rPtTJDCOfuypEWomjWxl5ODFBqGlSF/XlQf/JyIc8kVx +rTYpQw88PrULa2CaWwCFxYkPMxq0uWpbUJu039b+HYDfOwgyrCzZL3zoCyg5M4db +8u8BSAUz1F9XpDez8BPGSfGGK4scUXKKo/tE0ww9T38GZi+zo8JDOpo790F9bd+Q +ZilNzAF9FP1IqcomcWn8vYQN8N1J5dzV1tiHEM3Ppg6WhXPKRVKXABMf/PRQr1Zm +7XHVc3579/hpzMvWPMDzpbFhC713MJyVyDVJYsraeVw6pxD6UF+RUEkPdxB54sCH +tK8zKVEdUfDX4PhNKvArTvua +-----END CERTIFICATE----- diff --git a/packages/axum-server/tests/fixtures/https-health-check-key.pem b/packages/axum-server/tests/fixtures/https-health-check-key.pem new file mode 100644 index 0000000000..34fa25bf89 --- /dev/null +++ b/packages/axum-server/tests/fixtures/https-health-check-key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDUC5ycf7iapE/0 +PUWt3Tj60buIJJBDEVJXhi8mlZDnho0J+7dZYH2IsuHe2Ha4ADWNKYiMfqTSSsbo +9efFs8yvIl6S3UHxJphL82XQhRcucD4QlYI4jroLo+PrjqI3WCbpf6RW/H8fcMYB +btqRpn/PNrslyJDR+AOlE4lGgXfZRBIKPQTG+BXxmLGbrZe2nCyvEL4xS+d7MIBE +9ijmtwgA90tBwxh1j+jN6cmiuECGJkziMukGVJBoRnmrAG4ugRnPPAK8pYdp83HH +tFFB+rZjWXKz/HY3VrJE9WKHDn/SFZDeUpcg6xUHRmseMWjPoRtt/qDCwJU88wcT +X+7Wjya3AgMBAAECggEAXIOycT9yWhodfjjreUd/UEOIeAZH4NMiY2h6kvGHltRI +HdZysO6d5rHxRUqZRX9l3fCEkJPCsrOIZGTBmirvv2uV6qrZVe8aXGzV+6vNqOe0 +1IR+m9F9z41SaFhDYzU1SQP1PjSM/Dk2UrK8bva/ZbeB4KLIuKtmX7QN3TKoiSRU +A15rdI4SIbiZBsX7uxRy9beQkuxKsXObUju/RruKeUjNwh2zaY5uIQmCMMAehDKw +E4tJs6smXjRjIrtIZJW4hKqioqmNPAcBnfeTUq9Q7myLzckK6gPzAtsTKa8OHbwD +XcUeMG4t7xrmdHWkp73jaDmQ1rQl+s9/v7jwk9NMAQKBgQDumPb5Vl/E8ohH0gUU +KxuANs+NGXN68ZBSVujSDVUUJVRM42PYg5kjsxDEcMaR6qrnIgrmq6JINb55bgz8 +rHPgf9X0o67LSXjyS/QrvVFn1bBv+EqzNdbRt6k4uIlk/5+tBdUEpkKP+lxL/WwA +BKG7pBNsbVPHPGqK0JB8k44MAQKBgQDjgt8ajGKXfF+3qa2BUcxju8Bxnj3JB5xe +ECdeyUcVH+yBy9CfV6r8IqK8V26tmzK7VeXX/RoqESyb+dW7QXjX7tVze+qE8Z7R +wOcIHAaB5atRi1FZQq3fljWkQ8I09mfuZz475Le6Tilf5Vgaxt2Fb3mW15ExX2sJ +xXzkSSyStwKBgBGZUs49Yr8CLK8vfJRqQZMJd/GuaOgunTiVlIK53QapYjhxpVG5 +Ezig4qG6t8rXhleaGTe+fS/aVvxZ87dHeRycEUoEMMZp2vP0SkRXqIOCLYt0wv3J +ANljNKYsZmX+vOZkQbwgD1TTYK9yN98geFWA2rXqsn1FpY4rqByoPZgBAoGAE1i8 +qiBH/gPIi/C03WtcSxrbKY5ASMkJ5gHPp0LMdaJqVTtEuVgWJSy40/VHZyHsdXu/ +eNeAExW0ymq7XxoZMZuQsSpXbgix7bpOqyTe9MrX/64uM7301S+LzjUo3aIagm5r +H2K6sPAWmp4BGP3SNpedKlOYeC9aBdGyZiNG1A8CgYBryrhuwJ77gPGabS5P4HYI +MNQ/jkPSdeUPqrCbiod6tHUVR3a5K6aCEwE0iATiG9nb5HfVeZs8490v7k0zMJoY +s9CQ5Ayj3BHVH/GQHTxrQLzdrcvPlrSqIHiDXoIXLsUB7yc2xXzaRgvv7ajZ1on4 +Q5J3MeLdIHOHezMQm8V+MA== +-----END PRIVATE KEY----- diff --git a/packages/axum-server/tests/idle_connections.rs b/packages/axum-server/tests/idle_connections.rs new file mode 100644 index 0000000000..b993a70f1b --- /dev/null +++ b/packages/axum-server/tests/idle_connections.rs @@ -0,0 +1,317 @@ +//! Idle-connection regression tests for the shared Axum listener constructors +//! (issue #2776). +//! +//! Every test injects short timeouts and an absolute test deadline, so a +//! regression fails in a bounded time and never waits on the 5 s production +//! values. +use std::net::{SocketAddr, TcpListener}; +use std::sync::{Arc, Once}; +use std::time::Duration; + +use axum::Router; +use axum::routing::get; +use axum_server::Handle; +use axum_server::tls_rustls::RustlsConfig; +use rustls::RootCertStore; +use rustls::pki_types::pem::PemObject; +use rustls::pki_types::{CertificateDer, ServerName}; +use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt}; +use tokio::net::TcpStream; +use tokio::time::Instant; +use tokio_rustls::TlsConnector; +use torrust_tracker_axum_server::custom_axum_server::{self, Timeouts}; + +const CERTIFICATE: &[u8] = include_bytes!("fixtures/https-health-check-cert.pem"); +const KEY: &[u8] = include_bytes!("fixtures/https-health-check-key.pem"); + +/// Timeouts injected into the listener under test. +const SHORT: Duration = Duration::from_millis(300); + +/// Absolute bound: a connection the server still keeps open after this long is +/// reported as not closed. +const TEST_DEADLINE: Duration = Duration::from_secs(3); + +const fn short_timeouts() -> Timeouts { + Timeouts { + first_request: SHORT, + http1_header_read: SHORT, + http2_keep_alive_timeout: SHORT, + http2_keep_alive_interval: SHORT, + tls_handshake: SHORT, + } +} + +fn install_crypto_provider() { + static ONCE: Once = Once::new(); + ONCE.call_once(|| { + rustls::crypto::ring::default_provider() + .install_default() + .expect("ring should be the Rustls crypto provider for the tests"); + }); +} + +trait Io: AsyncRead + AsyncWrite + Unpin + Send {} +impl Io for T {} + +type Stream = Box; + +#[derive(Clone, Copy, Debug)] +enum Transport { + Plain, + Tls, +} + +struct TestServer { + addr: SocketAddr, + transport: Transport, + handle: Handle, +} + +impl Drop for TestServer { + fn drop(&mut self) { + self.handle.shutdown(); + } +} + +fn router() -> Router { + Router::new().route("/health_check", get(|| async { "OK" })) +} + +fn bind() -> TcpListener { + let socket = TcpListener::bind("127.0.0.1:0").expect("the test socket should bind"); + socket.set_nonblocking(true).expect("the socket should be non-blocking"); + socket +} + +async fn start(transport: Transport, timeouts: Timeouts) -> TestServer { + install_crypto_provider(); + + let socket = bind(); + let addr = socket.local_addr().expect("the socket should have an address"); + let handle = Handle::new(); + + match transport { + Transport::Plain => { + let server = custom_axum_server::from_tcp_with(socket, timeouts) + .expect("the plain server should be created") + .handle(handle.clone()); + tokio::spawn(server.serve(router().into_make_service())); + } + Transport::Tls => { + let tls = RustlsConfig::from_pem(CERTIFICATE.to_vec(), KEY.to_vec()) + .await + .expect("the test certificate should load"); + let server = custom_axum_server::from_tcp_rustls_with(socket, tls, timeouts) + .expect("the TLS server should be created") + .handle(handle.clone()); + tokio::spawn(server.serve(router().into_make_service())); + } + } + + TestServer { addr, transport, handle } +} + +async fn tls_connect(tcp: TcpStream, alpn: &[&[u8]]) -> std::io::Result { + let mut roots = RootCertStore::empty(); + roots + .add(CertificateDer::from_pem_slice(CERTIFICATE).expect("the test certificate should parse")) + .expect("the test certificate should be a valid root"); + let mut config = rustls::ClientConfig::builder() + .with_root_certificates(roots) + .with_no_client_auth(); + config.alpn_protocols = alpn.iter().map(|p| p.to_vec()).collect(); + + let name = ServerName::try_from("127.0.0.1").expect("an IP address is a valid server name"); + let stream = TlsConnector::from(Arc::new(config)).connect(name, tcp).await?; + + Ok(Box::new(stream)) +} + +impl TestServer { + /// Connects and completes the TLS handshake when the server uses TLS. + async fn connect(&self, alpn: &[&[u8]]) -> Stream { + let tcp = TcpStream::connect(self.addr).await.expect("the server should accept"); + + match self.transport { + Transport::Plain => Box::new(tcp), + Transport::Tls => tls_connect(tcp, alpn).await.expect("the TLS handshake should complete"), + } + } +} + +/// Reads until the server closes the connection. Returns the elapsed time, or +/// `None` if the connection is still open at the test deadline. +async fn closed_within_deadline(stream: &mut (impl AsyncRead + Unpin)) -> Option { + let start = Instant::now(); + let mut buffer = [0_u8; 1024]; + + tokio::time::timeout(TEST_DEADLINE, async { + loop { + match stream.read(&mut buffer).await { + Ok(0) | Err(_) => return, + Ok(_) => {} + } + } + }) + .await + .ok() + .map(|()| start.elapsed()) +} + +async fn read_until_contains(stream: &mut (impl AsyncRead + Unpin), needle: &[u8]) { + let mut received = Vec::new(); + let mut buffer = [0_u8; 1024]; + + tokio::time::timeout(TEST_DEADLINE, async { + while !received.windows(needle.len()).any(|w| w == needle) { + let n = stream.read(&mut buffer).await.expect("the response should be readable"); + assert!(n > 0, "the server closed before answering"); + received.extend_from_slice(&buffer[..n]); + } + }) + .await + .expect("the response should arrive before the test deadline"); +} + +const HTTP1_REQUEST: &[u8] = b"GET /health_check HTTP/1.1\r\nHost: localhost\r\n\r\n"; + +/// HTTP/2 client preface, an empty SETTINGS frame, and a `GET /` request on stream 1 (HPACK static table entries). +fn http2_request() -> Vec { + let mut bytes = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".to_vec(); + bytes.extend_from_slice(&[0, 0, 0, 4, 0, 0, 0, 0, 0]); // SETTINGS + let headers: Vec = [ + &[0x82_u8, 0x84, 0x86][..], // :method GET, :path /, :scheme http + &[0x01, 9][..], // :authority, literal value of length 9 + b"localhost", + ] + .concat(); + let len = u32::try_from(headers.len()).expect("a short header block"); + bytes.extend_from_slice(&len.to_be_bytes()[1..]); // 24-bit length + bytes.extend_from_slice(&[1, 0x05, 0, 0, 0, 1]); // HEADERS, END_STREAM | END_HEADERS, stream 1 + bytes.extend_from_slice(&headers); + bytes +} + +// A client that connects and sends nothing must be closed (AC1, AC2). + +#[tokio::test] +async fn it_should_close_a_plaintext_connection_that_sends_nothing() { + let server = start(Transport::Plain, short_timeouts()).await; + let mut stream = server.connect(&[]).await; + + let closed_after = closed_within_deadline(&mut stream).await; + + assert!(closed_after.is_some(), "a silent plaintext connection should be closed"); +} + +#[tokio::test] +async fn it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing() { + let server = start(Transport::Tls, short_timeouts()).await; + let mut stream = server.connect(&[]).await; + + let closed_after = closed_within_deadline(&mut stream).await; + + assert!(closed_after.is_some(), "a silent TLS connection should be closed"); +} + +// A TLS client that never completes the handshake must be closed (AC3). + +#[tokio::test] +async fn it_should_close_a_tls_connection_that_never_sends_handshake_bytes() { + let server = start(Transport::Tls, short_timeouts()).await; + let mut tcp = TcpStream::connect(server.addr).await.expect("the server should accept"); + + let closed_after = closed_within_deadline(&mut tcp).await; + + assert!(closed_after.is_some(), "a stalled TLS handshake should be closed"); +} + +#[tokio::test] +async fn it_should_close_a_tls_connection_that_sends_one_handshake_byte_and_stalls() { + let server = start(Transport::Tls, short_timeouts()).await; + let mut tcp = TcpStream::connect(server.addr).await.expect("the server should accept"); + tcp.write_all(&[0x16]).await.expect("one byte should be written"); + + let closed_after = closed_within_deadline(&mut tcp).await; + + assert!(closed_after.is_some(), "a half-sent TLS handshake should be closed"); +} + +// A persistent connection that is idle after a response must be closed (AC4). + +#[tokio::test] +async fn it_should_close_an_idle_http1_connection_after_a_response_over_plaintext() { + let server = start(Transport::Plain, short_timeouts()).await; + let mut stream = server.connect(&[]).await; + stream.write_all(HTTP1_REQUEST).await.expect("the request should be written"); + read_until_contains(&mut stream, b"OK").await; + + let closed_after = closed_within_deadline(&mut stream).await; + + assert!( + closed_after.is_some(), + "an idle HTTP/1 connection should be closed after its response" + ); +} + +#[tokio::test] +async fn it_should_close_an_idle_http1_connection_after_a_response_over_tls() { + let server = start(Transport::Tls, short_timeouts()).await; + let mut stream = server.connect(&[b"http/1.1"]).await; + stream.write_all(HTTP1_REQUEST).await.expect("the request should be written"); + read_until_contains(&mut stream, b"OK").await; + + let closed_after = closed_within_deadline(&mut stream).await; + + assert!( + closed_after.is_some(), + "an idle HTTP/1 TLS connection should be closed after its response" + ); +} + +#[tokio::test] +async fn it_should_close_an_idle_http2_connection_after_a_response_over_plaintext() { + let server = start(Transport::Plain, short_timeouts()).await; + let mut stream = server.connect(&[]).await; + stream + .write_all(&http2_request()) + .await + .expect("the request should be written"); + + // The client never acknowledges the server's keep-alive pings. + let closed_after = closed_within_deadline(&mut stream).await; + + assert!( + closed_after.is_some(), + "an idle HTTP/2 connection should be closed after its response" + ); +} + +#[tokio::test] +async fn it_should_close_an_idle_http2_connection_after_a_response_over_tls() { + let server = start(Transport::Tls, short_timeouts()).await; + let mut stream = server.connect(&[b"h2"]).await; + stream + .write_all(&http2_request()) + .await + .expect("the request should be written"); + + let closed_after = closed_within_deadline(&mut stream).await; + + assert!( + closed_after.is_some(), + "an idle HTTP/2 TLS connection should be closed after its response" + ); +} + +// The timeouts must not break a client that behaves. + +#[tokio::test] +async fn it_should_answer_a_request_sent_within_the_first_request_timeout() { + let server = start(Transport::Plain, short_timeouts()).await; + let mut stream = server.connect(&[]).await; + + stream.write_all(HTTP1_REQUEST).await.expect("the request should be written"); + + read_until_contains(&mut stream, b"200 OK").await; +} diff --git a/project-words.txt b/project-words.txt index bdc4d4e8b1..ed6bdcf8bd 100644 --- a/project-words.txt +++ b/project-words.txt @@ -149,6 +149,7 @@ alekitto alives alloca alnum +alpn analyse analysed appuser @@ -295,6 +296,7 @@ hostnames hotfixes hotspot hotspots +hpack httpclientpeerid hyperium hyperthread From e7a6ff7f1d25e3051ed50bb80cd51d483a4e3721 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 10 Nov 2026 17:00:44 +0000 Subject: [PATCH 03/13] fix(axum-server): [#2776] close idle connections with first_request_timeout Apply Server::first_request_timeout in the shared constructors and make the health check API use them instead of axum_server::from_tcp. Co-Authored-By: Claude Sonnet 5.5 --- .../evidence/red-run.txt | 1 + .../axum-health-check-api-server/Cargo.toml | 1 + .../src/server.rs | 42 ++++++++++++++++++- .../axum-server/src/custom_axum_server.rs | 3 +- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt index 1dc91ebf7f..ab9958256e 100644 --- a/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt +++ b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/red-run.txt @@ -8,3 +8,4 @@ test it_should_close_an_idle_http2_connection_after_a_response_over_tls ... ok test it_should_close_a_plaintext_connection_that_sends_nothing ... FAILED test it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing ... FAILED test result: FAILED. 7 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 3.00s +health check (old axum_server::from_tcp path): it_should_close_a_connection_that_sends_nothing FAILED after 8.00s (still open) diff --git a/packages/axum-health-check-api-server/Cargo.toml b/packages/axum-health-check-api-server/Cargo.toml index fd974c6777..1139311cca 100644 --- a/packages/axum-health-check-api-server/Cargo.toml +++ b/packages/axum-health-check-api-server/Cargo.toml @@ -44,6 +44,7 @@ url = { version = "2.5.4", features = [ "serde" ] } [dev-dependencies] reqwest = { version = "0", features = [ "json" ] } rustls = { version = "0.23", default-features = false, features = [ "ring" ] } +tokio = { version = "1", features = [ "io-util", "time" ] } torrust-tracker-axum-health-check-api-server = { path = ".", features = [ "testing" ] } torrust-tracker-axum-http-server = { version = "0.1.0", path = "../axum-http-server", features = [ "testing" ] } torrust-tracker-axum-rest-api-server = { version = "0.1.0", path = "../axum-rest-api-server", features = [ "testing" ] } diff --git a/packages/axum-health-check-api-server/src/server.rs b/packages/axum-health-check-api-server/src/server.rs index 380a928915..e06ae52963 100644 --- a/packages/axum-health-check-api-server/src/server.rs +++ b/packages/axum-health-check-api-server/src/server.rs @@ -24,6 +24,7 @@ use torrust_server_lib::registar::{Registar, RegistrationError, ServiceRegistrat reason = "legacy shutdown path on the deprecated `Halted` channel; SI-19 removes it" )] use torrust_server_lib::signals::{Halted, Started}; +use torrust_tracker_axum_server::custom_axum_server; #[allow( deprecated, reason = "deprecated legacy shutdown API kept for compatibility until SI-19 removes it" @@ -137,7 +138,7 @@ pub fn start( address, )); - let running = axum_server::from_tcp(socket)? + let running = custom_axum_server::from_tcp_with_timeouts(socket)? .handle(handle) .serve(router.into_make_service_with_connect_info::()); @@ -194,7 +195,7 @@ pub async fn start_with_cancellation( let service_binding = ServiceBinding::new(protocol.clone(), local_addr).map_err(|error| Error::Listener { source: std::io::Error::other(error), })?; - let server = axum_server::from_tcp(socket).map_err(|source| Error::Listener { source })?; + let server = custom_axum_server::from_tcp_with_timeouts(socket).map_err(|source| Error::Listener { source })?; let handle = Handle::new(); let serving = server @@ -451,6 +452,43 @@ mod tests { assert_eq!(drain_outcome, GracefulShutdownOutcome::Drained); } + /// A client that connects and sends nothing must be disconnected: an idle connection would hold a + /// task and a file descriptor for as long as the client keeps it open (issue #2776). + /// + /// The server uses the production first-request timeout (5 s), so the bound below is absolute and + /// generous instead of waiting without a bound. + #[tokio::test] + async fn it_should_close_a_connection_that_sends_nothing() { + use tokio::io::AsyncReadExt; + + // Arrange + let cancellation_token = CancellationToken::new(); + let running = start_with_cancellation( + any_available_port(), + Registar::default(), + Readiness::default(), + health_check_api_metadata(), + cancellation_token.clone(), + default_drain_timeout(), + ) + .await + .expect("the token-aware health check API should start"); + let mut silent_connection = tokio::net::TcpStream::connect(running.local_addr) + .await + .expect("open the silent connection"); + + // Act + let mut buffer = [0_u8; 16]; + let closed = tokio::time::timeout(Duration::from_secs(8), silent_connection.read(&mut buffer)).await; + + // Assert + assert!( + matches!(closed, Ok(Ok(0) | Err(_))), + "the health check API should close a connection that sends nothing: {closed:?}" + ); + cancellation_token.cancel(); + } + #[tokio::test] async fn it_should_time_out_the_drain_after_the_configured_drain_timeout_when_a_connection_stays_open() { // Arrange diff --git a/packages/axum-server/src/custom_axum_server.rs b/packages/axum-server/src/custom_axum_server.rs index 85aacfd271..bf7030417e 100644 --- a/packages/axum-server/src/custom_axum_server.rs +++ b/packages/axum-server/src/custom_axum_server.rs @@ -119,7 +119,8 @@ fn add_timeouts(mut server: Server, .keep_alive_timeout(timeouts.http2_keep_alive_timeout) .keep_alive_interval(timeouts.http2_keep_alive_interval); - server + // Closes connections that never send a complete first request, for plaintext and TLS (after the handshake). + server.first_request_timeout(timeouts.first_request) } #[derive(Clone)] From 167841cd3ec7190e37c2b7d3b87f1f53bf6849f9 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 10 Nov 2026 17:09:03 +0000 Subject: [PATCH 04/13] refactor(axum-server): [#2776] remove the TimeoutAcceptor wrapper first_request_timeout, the Hyper header read timeout and HTTP/2 keep-alive bound every idle case the wrapper bounded (same probe results with and without it, HTTP/1 and HTTP/2), and they also cover TLS and the health check API. Drop TimeoutAcceptor, TimeoutStream, TimeoutService, TimeoutBody and the dependencies only they used. Co-Authored-By: Claude Sonnet 5.5 --- Cargo.lock | 5 - packages/axum-http-server/src/server.rs | 3 +- packages/axum-rest-api-server/src/server.rs | 7 +- packages/axum-server/Cargo.toml | 5 - .../axum-server/src/custom_axum_server.rs | 243 +----------------- 5 files changed, 15 insertions(+), 248 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6addb71f18..6d315c92cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5073,11 +5073,7 @@ dependencies = [ "axum", "axum-server", "camino", - "futures-util", - "http-body", - "hyper", "hyper-util", - "pin-project-lite", "rustls", "thiserror 2.0.21", "tokio", @@ -5086,7 +5082,6 @@ dependencies = [ "torrust-located-error", "torrust-server-lib", "torrust-tracker-configuration", - "tower", "tracing", ] diff --git a/packages/axum-http-server/src/server.rs b/packages/axum-http-server/src/server.rs index 7027d5be49..ac2fc0f75c 100644 --- a/packages/axum-http-server/src/server.rs +++ b/packages/axum-http-server/src/server.rs @@ -21,7 +21,7 @@ use torrust_server_lib::registar::{ reason = "legacy shutdown path on the deprecated `Halted` channel; SI-19 removes it" )] use torrust_server_lib::signals::{Halted, Started}; -use torrust_tracker_axum_server::custom_axum_server::{self, TimeoutAcceptor}; +use torrust_tracker_axum_server::custom_axum_server; #[allow( deprecated, reason = "deprecated legacy shutdown API kept for compatibility until SI-19 removes it" @@ -152,7 +152,6 @@ impl Launcher { Ok(Box::pin(async move { if let Err(error) = server .handle(handle) - .acceptor(TimeoutAcceptor) .serve(app.into_make_service_with_connect_info::()) .await { diff --git a/packages/axum-rest-api-server/src/server.rs b/packages/axum-rest-api-server/src/server.rs index 0bde9ecf7d..1d5a2a4113 100644 --- a/packages/axum-rest-api-server/src/server.rs +++ b/packages/axum-rest-api-server/src/server.rs @@ -44,7 +44,7 @@ use torrust_server_lib::registar::{ServiceHealthCheckJob, ServiceRegistration, S reason = "legacy shutdown path on the deprecated `Halted` channel; SI-19 removes it" )] use torrust_server_lib::signals::{Halted, Started}; -use torrust_tracker_axum_server::custom_axum_server::{self, TimeoutAcceptor}; +use torrust_tracker_axum_server::custom_axum_server; #[allow( deprecated, reason = "deprecated legacy shutdown API kept for compatibility until SI-19 removes it" @@ -373,7 +373,6 @@ fn start_token_aware_runtime( Box::pin(async move { if let Err(error) = server .handle(server_handle) - .acceptor(TimeoutAcceptor) .serve(router.into_make_service_with_connect_info::()) .await { @@ -564,9 +563,6 @@ impl Launcher { Box::pin(async move { if let Err(error) = server .handle(handle) - // The TimeoutAcceptor is commented because TLS does not work with it. - // See: https://github.com/torrust/torrust-index/issues/204#issuecomment-2115529214 - //.acceptor(TimeoutAcceptor) .serve(router.into_make_service_with_connect_info::()) .await { @@ -578,7 +574,6 @@ impl Launcher { Box::pin(async move { if let Err(error) = server .handle(handle) - .acceptor(TimeoutAcceptor) .serve(router.into_make_service_with_connect_info::()) .await { diff --git a/packages/axum-server/Cargo.toml b/packages/axum-server/Cargo.toml index 81b7e482bd..b46473ed6f 100644 --- a/packages/axum-server/Cargo.toml +++ b/packages/axum-server/Cargo.toml @@ -19,18 +19,13 @@ workspace = true [dependencies] axum-server = { version = "0.9", features = [ "tls-rustls-no-provider" ] } camino = { version = "1", features = [ "serde", "serde1" ] } -futures-util = "0" -http-body = "1" -hyper = "1" hyper-util = { version = "0", features = [ "http1", "http2", "tokio" ] } -pin-project-lite = "0" thiserror = "2" tokio = { version = "1", features = [ "macros", "net", "rt-multi-thread", "signal", "sync" ] } tokio-util = { version = "0.7", features = [ "rt" ] } torrust-server-lib = "0.5.0" torrust-tracker-configuration = { version = "3.0.0", path = "../configuration" } torrust-located-error = "3.0.0" -tower = { version = "0", features = [ "timeout" ] } tracing = "0" [dev-dependencies] diff --git a/packages/axum-server/src/custom_axum_server.rs b/packages/axum-server/src/custom_axum_server.rs index bf7030417e..8f883fbd94 100644 --- a/packages/axum-server/src/custom_axum_server.rs +++ b/packages/axum-server/src/custom_axum_server.rs @@ -1,11 +1,8 @@ -//! Wrapper for Axum server to add timeouts. +//! Constructors for the Axum servers with the tracker's connection timeouts. //! -//! Copyright (c) Eray Karatay ([@programatik29](https://github.com/programatik29)). -//! -//! See: . -//! -//! If a client opens a HTTP connection and it does not send any requests, the -//! connection is closed after a timeout. You can test it with: +//! A client that opens a connection and never sends a request is disconnected +//! after [`Timeouts::first_request`], for plaintext and TLS listeners. You can +//! test it with: //! //! ```text //! telnet 127.0.0.1 1212 @@ -15,26 +12,22 @@ //! Connection closed by foreign host. //! ``` //! +//! The server closes the connection without sending a `408` response. +//! +//! The timeouts come from `axum-server` 0.9 (`Server::first_request_timeout`, a +//! default timer and the TLS handshake timeout) and from Hyper (header read +//! timeout and HTTP/2 keep-alive). They replace the `TimeoutAcceptor` copied +//! from [programatik29's gist](https://gist.github.com/programatik29/36d371c657392fd7f322e7342957b6d1), +//! which did not work with TLS and did not cover the health check API. See +//! issue #2776. +//! //! If you want to know more about Axum and timeouts see . -use std::future::Ready; -use std::io::ErrorKind; use std::net::{SocketAddr, TcpListener}; -use std::pin::Pin; -use std::task::{Context, Poll}; use std::time::Duration; use axum_server::Server; -use axum_server::accept::Accept; use axum_server::tls_rustls::{RustlsAcceptor, RustlsConfig}; -use futures_util::{Future, ready}; -use http_body::{Body, Frame}; -use hyper::Response; use hyper_util::rt::TokioTimer; -use pin_project_lite::pin_project; -use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; -use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; -use tokio::time::{Instant, Sleep}; -use tower::Service; type RustlsServerResult = Result, std::io::Error>; type ServerResult = Result, std::io::Error>; @@ -122,213 +115,3 @@ fn add_timeouts(mut server: Server, // Closes connections that never send a complete first request, for plaintext and TLS (after the handshake). server.first_request_timeout(timeouts.first_request) } - -#[derive(Clone)] -pub struct TimeoutAcceptor; - -impl Accept for TimeoutAcceptor { - type Stream = TimeoutStream; - type Service = TimeoutService; - type Future = Ready>; - - fn accept(&self, stream: I, service: S) -> Self::Future { - let (tx, rx) = mpsc::unbounded_channel(); - - let stream = TimeoutStream::new(stream, Timeouts::default().http1_header_read, rx); - let service = TimeoutService::new(service, tx); - - std::future::ready(Ok((stream, service))) - } -} - -#[derive(Clone)] -pub struct TimeoutService { - inner: S, - sender: UnboundedSender, -} - -impl TimeoutService { - const fn new(inner: S, sender: UnboundedSender) -> Self { - Self { inner, sender } - } -} - -impl Service for TimeoutService -where - S: Service>, -{ - type Response = Response>; - type Error = S::Error; - type Future = TimeoutServiceFuture; - - fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - self.inner.poll_ready(cx) - } - - fn call(&mut self, req: Request) -> Self::Future { - // send timer wait signal - let _ = self.sender.send(TimerSignal::Wait); - - TimeoutServiceFuture::new(self.inner.call(req), self.sender.clone()) - } -} - -pin_project! { - pub struct TimeoutServiceFuture { - #[pin] - inner: F, - sender: Option>, - } -} - -impl TimeoutServiceFuture { - const fn new(inner: F, sender: UnboundedSender) -> Self { - Self { - inner, - sender: Some(sender), - } - } -} - -impl Future for TimeoutServiceFuture -where - F: Future, E>>, -{ - type Output = Result>, E>; - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = self.project(); - this.inner.poll(cx).map(|result| { - result.map(|response| { - response.map(|body| TimeoutBody::new(body, this.sender.take().expect("future polled after ready"))) - }) - }) - } -} - -enum TimerSignal { - Wait, - Reset, -} - -pin_project! { - pub struct TimeoutBody { - #[pin] - inner: B, - sender: UnboundedSender, - } -} - -impl TimeoutBody { - const fn new(inner: B, sender: UnboundedSender) -> Self { - Self { inner, sender } - } -} - -impl Body for TimeoutBody { - type Data = B::Data; - type Error = B::Error; - - fn poll_frame(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll, Self::Error>>> { - let this = self.project(); - let option = ready!(this.inner.poll_frame(cx)); - - if option.is_none() { - let _ = this.sender.send(TimerSignal::Reset); - } - - Poll::Ready(option) - } - - fn is_end_stream(&self) -> bool { - let is_end_stream = self.inner.is_end_stream(); - - if is_end_stream { - let _ = self.sender.send(TimerSignal::Reset); - } - - is_end_stream - } - - fn size_hint(&self) -> http_body::SizeHint { - self.inner.size_hint() - } -} - -pub struct TimeoutStream { - inner: IO, - // hyper requires unpin - sleep: Pin>, - duration: Duration, - waiting: bool, - receiver: UnboundedReceiver, - finished: bool, -} - -impl TimeoutStream { - fn new(inner: IO, duration: Duration, receiver: UnboundedReceiver) -> Self { - Self { - inner, - sleep: Box::pin(tokio::time::sleep(duration)), - duration, - waiting: false, - receiver, - finished: false, - } - } -} - -impl AsyncRead for TimeoutStream { - fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll> { - if !self.finished { - match Pin::new(&mut self.receiver).poll_recv(cx) { - // reset the timer - Poll::Ready(Some(TimerSignal::Reset)) => { - self.waiting = false; - - let deadline = Instant::now() + self.duration; - self.sleep.as_mut().reset(deadline); - } - // enter waiting mode (for response body last chunk) - Poll::Ready(Some(TimerSignal::Wait)) => self.waiting = true, - Poll::Ready(None) => self.finished = true, - Poll::Pending => (), - } - } - - if !self.waiting { - // return error if timer is elapsed - if self.sleep.as_mut().poll(cx) == Poll::Ready(()) { - return Poll::Ready(Err(std::io::Error::new(ErrorKind::TimedOut, "request header read timed out"))); - } - } - - Pin::new(&mut self.inner).poll_read(cx, buf) - } -} - -impl AsyncWrite for TimeoutStream { - fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { - Pin::new(&mut self.inner).poll_write(cx, buf) - } - - fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.inner).poll_flush(cx) - } - - fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - Pin::new(&mut self.inner).poll_shutdown(cx) - } - - fn poll_write_vectored( - mut self: Pin<&mut Self>, - cx: &mut Context<'_>, - bufs: &[std::io::IoSlice<'_>], - ) -> Poll> { - Pin::new(&mut self.inner).poll_write_vectored(cx, bufs) - } - - fn is_write_vectored(&self) -> bool { - self.inner.is_write_vectored() - } -} From 024eb565aebd7cd9494563392eb77c999aa8c8b0 Mon Sep 17 00:00:00 2001 From: josecelano-bot Date: Tue, 10 Nov 2026 17:16:02 +0000 Subject: [PATCH 05/13] docs(issues): [#2776] record evidence, decisions and EPIC #2411 case A2 update Co-Authored-By: Claude Sonnet 5.5 --- .../2411-spam-and-abuse-resistance/EPIC.md | 13 +- .../ISSUE.md | 79 ++++++------ .../evidence/probe-h2.py | 23 ++++ .../evidence/results-final-build.txt | 14 +++ .../evidence/results-with-wrapper.txt | 14 +++ .../evidence/results-without-wrapper.txt | 14 +++ .../evidence/run-probes.sh | 27 ++++ .../manual-verification-evidence.md | 119 ++++++++++++++++-- 8 files changed, 250 insertions(+), 53 deletions(-) create mode 100644 docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/probe-h2.py create mode 100644 docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/results-final-build.txt create mode 100644 docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/results-with-wrapper.txt create mode 100644 docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/results-without-wrapper.txt create mode 100755 docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/run-probes.sh diff --git a/docs/issues/open/2411-spam-and-abuse-resistance/EPIC.md b/docs/issues/open/2411-spam-and-abuse-resistance/EPIC.md index 607e4300ca..14b5edfa53 100644 --- a/docs/issues/open/2411-spam-and-abuse-resistance/EPIC.md +++ b/docs/issues/open/2411-spam-and-abuse-resistance/EPIC.md @@ -6,7 +6,7 @@ epic: null github-issue: 2411 spec-path: docs/issues/open/2411-spam-and-abuse-resistance/EPIC.md epic-owner: josecelano -last-updated-utc: "2026-10-07 15:47" +last-updated-utc: "2026-11-10 17:20" semantic-links: skill-links: - create-issue @@ -54,7 +54,7 @@ Add a row for every new case. "Source" says where it was found. | ID | Case | Affected | Effect | Status | Source | | --- | --- | --- | --- | --- | --- | | A1 | No shared configurable request-rate policy | UDP, HTTP, REST API, health check | Aggregate work can exceed capacity despite existing local protections | Confirmed: no service has a request-rate policy; HTTP, REST API and health check have no concurrency or connection limit; UDP has only connection-ID banning and an approximate active-request ring. Hypothesis: the capacity at which aggregate work degrades service; confirm by measuring throughput and latency under parallel load on an isolated local tracker | Known limitation | -| A2 | Connections without a client timeout | HTTP, REST API, health check | Idle connections hold resources | Confirmed: the HTTP tracker and REST API bound header reads and handler work to 5 s, and their plaintext listeners close a connection idle for 5 s, but TLS listeners omit that idle-connection acceptor; the health check API sets none of these timeouts. Hypothesis: whether idle TLS and health check connections are ever closed; confirm by holding idle connections against an isolated local tracker | #324 | +| A2 | Connections without a client timeout | HTTP, REST API, health check | Idle connections hold resources | Mitigated by #2776 (`axum-server` 0.9): every Axum listener, plaintext and TLS, closes a connection that sends no complete first request within 5 s (`Server::first_request_timeout`), and closes one that is idle after a response (5 s for HTTP/1, about 10 s for HTTP/2); a TLS handshake that does not complete is closed after 10 s. Verified at runtime on the final build ([evidence](../2776-2411-axum-server-0-9-timeouts/manual-verification-evidence.md)). The server closes the connection without a `408`; the values are not configurable | #324, #2776 | | A3 | HTTP scrape exceeds the documented 74 info-hash limit | HTTP tracker | Local requests returned 75 and 1000 entries; overload impact not measured | Decided in #2417: HTTP keeps the first 100 as a per-request policy cap ([ADR](../../../adrs/20261005124222_cap_scrape_info_hashes_per_protocol.md)); total load still needs rate limiting | [HTTP limit evidence](../../closed/2417-2411-verify-http-scrape-info-hash-limit/manual-verification-evidence.md) | | A4 | Announce for new info hashes adds torrents to memory when policy permits | UDP, HTTP tracker | Memory is retained while peers remain active; expiry and optional peerless cleanup affect retention | Confirmed: with the default `listed = false` every info hash is authorized and its first announce adds a swarm, with no cap on the number of swarms; a swarm stays until its peers expire and peerless cleanup removes it, and stays indefinitely when `remove_peerless_torrents = false` or cleanup is disabled. Hypothesis: memory per swarm and its growth rate; confirm by measuring resident memory against distinct announced info hashes | SI-22 session, 2026-10-02 | | A5 | First announce of an unknown torrent reads the database when persistence is enabled | UDP, HTTP tracker | Database load from random info hashes | Confirmed: an announce for a swarm absent from memory reads the database once when `persistent_torrent_completed_stat` is enabled (default `false`); the swarm it then adds (A4) prevents re-reads until eviction. Hypothesis: database load at a given rate of new info hashes; confirm by counting queries and latency on an isolated local tracker | `AnnounceHandler::load_downloads_metric_if_needed` | @@ -75,7 +75,7 @@ Notes: newly discovered security-sensitive details. - Review basis: a "Confirmed" status was read from the code at `050726d46`, not reproduced at runtime; each "Hypothesis" names the measurement that would confirm it. A3's status records the #2417 decision, whose evidence includes runtime checks (V1 to V3). The `path:line` citations resolve at `7970cdf0a`. Issue #2458 later replaced the module that created the UDP connection-ID key, so the UDP connection-ID control row names the key's creation by symbol instead of by line. [Existing Controls](#existing-controls) lists the protections each case relies on. - A1: no rate limiter, semaphore or connection limit exists in the HTTP tracker, REST API or health check API servers; the UDP ring is not an exact bound (`packages/udp-server/src/server/request_buffer.rs:20`); `interval_min` is advertised to clients (`packages/http-protocol/src/v1/responses/announce/encoding.rs:66`) but not enforced. -- A2: the idle-connection acceptor (`packages/axum-server/src/custom_axum_server.rs:89`) is applied only to plaintext listeners (`packages/axum-http-server/src/server.rs:145`, `packages/axum-rest-api-server/src/server.rs:314`); the REST API records why TLS omits it (`packages/axum-rest-api-server/src/server.rs:464`); the health check API starts a plain server (`packages/axum-health-check-api-server/src/server.rs:154`). +- A2: all three Axum server packages build their listener through `from_tcp_with_timeouts` or `from_tcp_rustls_with_timeouts` (`packages/axum-server/src/custom_axum_server.rs:71`, `packages/axum-server/src/custom_axum_server.rs:89`), which set the first-request, header-read and HTTP/2 keep-alive timeouts and the TLS handshake timeout (`packages/axum-server/src/custom_axum_server.rs:104`); the health check API uses the same constructor (`packages/axum-health-check-api-server/src/server.rs:141`). The earlier `TimeoutAcceptor` copy of a gist, which skipped TLS and the health check API, was removed in #2776. - A3: UDP keeps the first 74 hashes (`packages/udp-protocol/src/request.rs:34`) and its 1496-byte receive buffer (`packages/udp-server/src/server/receiver.rs:15`) cannot carry more; HTTP keeps the first 100 `info_hash` parameters (`packages/http-protocol/src/v1/requests/scrape.rs:25`, `packages/http-protocol/src/v1/requests/scrape.rs:78`) and ignores the rest without decoding them, as its documentation states (`packages/axum-http-server/src/lib.rs:235`); the cap bounds decoding, not the parsing of the query string, which only the HTTP request size control bounds. - A4: authorization passes every info hash unless the tracker is listed (`packages/tracker-core/src/whitelist/authorization.rs:51`); the first announce inserts the swarm (`packages/swarm-coordination-registry/src/swarm/registry.rs:61`); a peerless swarm is removed only when `remove_peerless_torrents` is set (`packages/swarm-coordination-registry/src/swarm/coordinator.rs:205`); cleanup is not scheduled when `inactive_peer_cleanup_interval` is `0` (`src/app.rs:535`). - A5: the memory check and the read are `packages/tracker-core/src/announce_handler.rs:199` and `packages/tracker-core/src/announce_handler.rs:203`; nothing serializes them, which is consistent with the concurrent double read noted above; eviction is peerless cleanup (`packages/swarm-coordination-registry/src/swarm/registry.rs:294`). @@ -96,9 +96,10 @@ Each control bounds one cost locally; none bounds aggregate work across requests | UDP datagram size | `packages/udp-protocol/src/common.rs:19` | One 1496-byte receive buffer per datagram (`packages/udp-server/src/server/receiver.rs:15`) | Not configurable | A3 | | UDP scrape count | `packages/udp-protocol/src/request.rs:34` | First 74 info hashes per scrape, the rest ignored (`packages/udp-protocol/src/request.rs:145`), with the cap passed by the server (`packages/udp-server/src/handlers/mod.rs:87`) | Not configurable, 74: `MAX_SCRAPE_INFO_HASHES` in `udp-protocol`, computed from the datagram size | A3 | | HTTP scrape count | `packages/http-protocol/src/v1/requests/scrape.rs:25` | First 100 `info_hash` parameters per request, the rest ignored without decoding (`packages/http-protocol/src/v1/requests/scrape.rs:78`) | Not configurable, 100: `MAX_SCRAPE_INFO_HASHES` in `http-protocol` | A3 | -| HTTP request size | `packages/axum-server/src/custom_axum_server.rs:68`, `packages/axum-server/src/custom_axum_server.rs:72`: only the header-read and keep-alive timeouts are set; no header or URI size limit is configured, so Hyper's default buffer limit applies | The bytes of a request, and so the parsing of its query string: the scrape extractor parses the whole query (`packages/axum-http-server/src/v1/extractors/scrape_request.rs:70`), `Query::from_str` splits it and inserts every `name=value` pair into a `MultiMap` (`packages/http-protocol/src/v1/query.rs:112`, `packages/http-protocol/src/v1/query.rs:120`), and only then `Scrape::try_from` applies the 100 cap (`packages/http-protocol/src/v1/requests/scrape.rs:66`) | None | A1, A3 | -| HTTP idle-connection timeout | `packages/axum-server/src/custom_axum_server.rs:89` | Closes a plaintext HTTP tracker or REST API connection that completes no request within 5 s of opening or of the last response | Not configurable, 5 s (`packages/axum-server/src/custom_axum_server.rs:42`) | A2 | -| HTTP header-read and HTTP/2 keep-alive timeouts | `packages/axum-server/src/custom_axum_server.rs:68` | HTTP/1 request headers within 5 s; HTTP/2 keep-alive pings (`packages/axum-server/src/custom_axum_server.rs:72`); HTTP tracker and REST API, plaintext and TLS | Not configurable, 5 s | A2 | +| HTTP request size | `packages/axum-server/src/custom_axum_server.rs:104`: only the first-request, header-read and keep-alive timeouts are set; no header or URI size limit is configured, so Hyper's default buffer limit applies | The bytes of a request, and so the parsing of its query string: the scrape extractor parses the whole query (`packages/axum-http-server/src/v1/extractors/scrape_request.rs:70`), `Query::from_str` splits it and inserts every `name=value` pair into a `MultiMap` (`packages/http-protocol/src/v1/query.rs:112`, `packages/http-protocol/src/v1/query.rs:120`), and only then `Scrape::try_from` applies the 100 cap (`packages/http-protocol/src/v1/requests/scrape.rs:66`) | None | A1, A3 | +| HTTP first-request timeout | `packages/axum-server/src/custom_axum_server.rs:116` | Closes a connection of the HTTP tracker, REST API or health check API that sends no complete first request within 5 s, plaintext and TLS (after the handshake); no `408` | Not configurable, 5 s: `Timeouts::default` (`packages/axum-server/src/custom_axum_server.rs:54`); injectable in tests | A2 | +| HTTP header-read and HTTP/2 keep-alive timeouts | `packages/axum-server/src/custom_axum_server.rs:104` | HTTP/1 request headers within 5 s, which also closes an idle keep-alive connection 5 s after a response; HTTP/2 keep-alive pings every 5 s with a 5 s reply wait, so an idle HTTP/2 connection that does not answer pings closes after about 10 s; all three Axum listeners, plaintext and TLS | Not configurable, 5 s: `Timeouts::default` (`packages/axum-server/src/custom_axum_server.rs:54`) | A2 | +| TLS handshake timeout | `packages/axum-server/src/custom_axum_server.rs:98` | Closes a TLS connection that does not complete the handshake within 10 s (`RustlsAcceptor::handshake_timeout`) | Not configurable, 10 s: `Timeouts::default` (`packages/axum-server/src/custom_axum_server.rs:54`) | A2 | | HTTP per-request timeout | `packages/axum-http-server/src/v1/routes.rs:161` | Handler work over 5 s answers `408` on the HTTP tracker and the REST API (`packages/axum-rest-api-server/src/routes.rs:145`) | Not configurable, 5 s (`packages/axum-http-server/src/v1/routes.rs:28`) | A1, A2 | | Announce response size | `packages/tracker-core/src/announce_handler.rs:218` | Peers returned per announce, not peers stored | `core.announce_policy.max_peers_per_announce`, 74 (`packages/primitives/src/announce.rs:81`) | A7 | | Peer expiry and peerless cleanup | `packages/tracker-core/src/torrent/manager.rs:104` | Removes peers idle longer than `max_peer_timeout`, then peerless swarms when enabled (`packages/tracker-core/src/torrent/manager.rs:108`) | `core.tracker_policy.max_peer_timeout`, 900 s (`packages/primitives/src/policy.rs:59`); `core.inactive_peer_cleanup_interval`, 600 s, `0` disables (`packages/configuration/src/v3_0_0/core.rs:80`); `core.tracker_policy.remove_peerless_torrents`, `true` (`packages/primitives/src/policy.rs:67`) | A4, A5, A7 | diff --git a/docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md index 03b9e371ec..46811fe03f 100644 --- a/docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md +++ b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md @@ -2,14 +2,14 @@ schema-version: 1 doc-type: issue issue-type: bug -status: planned +status: in-progress priority: p2 epic: 2411 github-issue: 2776 spec-path: docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md branch: "2776-axum-server-0-9-timeouts-spec" related-pr: null -last-updated-utc: "2026-11-06 21:10" +last-updated-utc: "2026-11-10 17:30" semantic-links: skill-links: - create-issue @@ -174,14 +174,14 @@ Status values: `TODO`, `IN_PROGRESS`, `BLOCKED`, `DONE`. | ID | Status | Task | Notes / Expected Output | | --- | ------ | -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | T1 | DONE | Reproduce current behaviour on plaintext, TLS and health check listeners | Baseline recorded in `manual-verification-evidence.md`: TLS and health check reproduced | -| T2 | TODO | Bump `axum-server` to 0.9 and fix compile or behaviour breakage | `"0.9"` required in the root and all four Axum package manifests; `Cargo.lock` 0.9.x | -| T3 | TODO | Add red regression tests: idle plaintext and TLS, stalled handshake, post-response idle | Recorded red run before the fix; TLS and health check tests fail on the current code | -| T4 | TODO | Apply `first_request_timeout` through one constructor path used by all three server packages | All listeners close idle connections; tests green | -| T5 | TODO | Compare idle bounds with and without `TimeoutAcceptor`, HTTP/1 and HTTP/2, then decide | Evidence from M4 for both builds and both protocols; wrapper removed, or kept with reason | -| T6 | TODO | Decide timeout configurability; record the TLS handshake timeout behaviour | Progress-log decision; constants or configuration keys documented | -| T7 | TODO | Update EPIC #2411 case A2 and controls, remove stale comments, update docs | EPIC rows match the new behaviour; no stale "TLS does not work" comments | +| T2 | DONE | Bump `axum-server` to 0.9 and fix compile or behaviour breakage | `"0.9"` required in the root and all four Axum package manifests; `Cargo.lock` 0.9.x | +| T3 | DONE | Add red regression tests: idle plaintext and TLS, stalled handshake, post-response idle | Recorded red run before the fix; TLS and health check tests fail on the current code | +| T4 | DONE | Apply `first_request_timeout` through one constructor path used by all three server packages | All listeners close idle connections; tests green | +| T5 | DONE | Compare idle bounds with and without `TimeoutAcceptor`, HTTP/1 and HTTP/2, then decide | Evidence from M4 for both builds and both protocols; wrapper removed, or kept with reason | +| T6 | DONE | Decide timeout configurability; record the TLS handshake timeout behaviour | Progress-log decision; constants or configuration keys documented | +| T7 | DONE | Update EPIC #2411 case A2 and controls, remove stale comments, update docs | EPIC rows match the new behaviour; no stale "TLS does not work" comments | | T8 | TODO | Close or link #324, #612, #613 and #603 checklist | Maintainer action; issue links recorded in the progress log | -| T9 | TODO | Green run and final like-for-like recheck after the last production change | T1 probes repeated on the final build, named by its Conventional Commit subject | +| T9 | DONE | Green run and final like-for-like recheck after the last production change | T1 probes repeated on the final build, named by its Conventional Commit subject | ## Commit Points @@ -209,10 +209,10 @@ with GPG. - [x] Spec reviewed and approved by user/maintainer - [x] GitHub issue created and issue number added to this spec (#2776) - [ ] (Optional, recommended for complex issues) Spec-only PR merged into `develop` before implementation -- [ ] Implementation completed -- [ ] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks) -- [ ] Manual verification scenarios executed and recorded in issue-local `manual-verification-evidence.md` -- [ ] Acceptance criteria reviewed after implementation and updated with evidence +- [x] Implementation completed +- [x] Automatic verification completed (`linter all`, relevant tests, and any pre-push checks) +- [x] Manual verification scenarios executed and recorded in issue-local `manual-verification-evidence.md` +- [x] Acceptance criteria reviewed after implementation and updated with evidence - [ ] Evidence-based implementation completion review recorded: issue-local retrospective created for material discoveries, or progress log states why none was needed - [ ] Reviewer validated acceptance criteria and updated checkboxes - [ ] Independent reviewer reports recorded in issue-local `agent-review-reports.md` when reviewers received this folder-style specification @@ -224,21 +224,22 @@ with GPG. - 2026-11-06 18:30 UTC - Claude Code (Claude Sonnet 5.5) - Drafted after `axum-server` issue #116 was closed and 0.9.0 was released; analysed #324, #603, #612, #613 and EPIC #2411 case A2. Nothing was run against the tracker at that point. - 2026-11-06 18:45 UTC - Claude Code (Claude Sonnet 5.5) - Maintainer approved the draft; created issue #2776 and moved the spec to `open/`. - 2026-11-06 21:10 UTC - Claude Code (Claude Sonnet 5.5) - Answered the Copilot review on PR #2777: ran the baseline reproduction (Reproduced for TLS and the health check API; plaintext HTTP tracker and REST API close at 5 s), added the evidence file, required `"0.9"` in five manifests, added stalled-handshake and post-response regression tests, a final recheck task (T9), with/without-wrapper comparison for HTTP/1 and HTTP/2, and split M5. - [evidence](manual-verification-evidence.md) +- 2026-11-10 17:30 UTC - Claude Code (Claude Sonnet 5.5) - Implemented. T2: `axum-server` 0.9.0 required in five manifests (no source change needed; the tracker does not wrap a TLS acceptor, so `TlsService` did not matter). T3/T4: `custom_axum_server::Timeouts` (injectable) with `from_tcp_with`/`from_tcp_rustls_with`; `first_request_timeout` applied in the shared constructor path, and the health check API now uses it; red run recorded, tests green. Checkpoint after the plaintext HTTP slice: the design held for all listeners without change. T5: with/without-wrapper comparison identical for HTTP/1 and HTTP/2, so `TimeoutAcceptor`, `TimeoutStream`, `TimeoutService`, `TimeoutBody` were removed (no ADR: the replacement is the upstream feature and the behaviour is recorded in the EPIC controls). T6 decision: the values stay constants in `Timeouts::default` (5 s first request, header read and HTTP/2 keep-alive; 10 s TLS handshake), injectable in code for tests, not configuration keys, because nothing in the evidence asks operators to tune them; revisit under EPIC #2411 case A1. Known limitations: the server closes without `408`; HTTP/2 idle bound is 10 s; a client that answers HTTP/2 pings is not time-bounded. T7: EPIC case A2 and controls updated. T9: final recheck on commit `167841cd3`. T8 is the maintainer's. No retrospective needed: no discovery changed the design beyond the HTTP/2 measurement already recorded in the evidence. - [evidence](manual-verification-evidence.md) ## Acceptance Criteria -- [ ] AC1: A client that connects to the HTTP tracker, REST API or health check API over plaintext and sends nothing is disconnected within the configured first-request timeout. -- [ ] AC2: The same holds for TLS connections of the HTTP tracker and REST API after the handshake completes. -- [ ] AC3: A slow or stalled TLS handshake is bounded, and the bound is recorded in the documentation. -- [ ] AC4: An idle persistent connection after a response, HTTP/1 and HTTP/2, is closed in bounded time no worse than today's plaintext 5 s, measured on the replacement build; a weaker result blocks the removal in AC5 and is recorded in EPIC #2411. -- [ ] AC5: `TimeoutAcceptor` and its helper types are removed only after AC4 is shown by a comparison with and without the wrapper for HTTP/1 and HTTP/2; otherwise the spec records why they stay. -- [ ] AC6: EPIC #2411 case A2 and the existing-controls rows describe the new behaviour; the stale "TLS does not work" comments are gone. +- [x] AC1: A client that connects to the HTTP tracker, REST API or health check API over plaintext and sends nothing is disconnected within the configured first-request timeout. +- [x] AC2: The same holds for TLS connections of the HTTP tracker and REST API after the handshake completes. +- [x] AC3: A slow or stalled TLS handshake is bounded, and the bound is recorded in the documentation. +- [x] AC4: An idle persistent connection after a response, HTTP/1 and HTTP/2, is closed in bounded time no worse than today's plaintext 5 s, measured on the replacement build; a weaker result blocks the removal in AC5 and is recorded in EPIC #2411. +- [x] AC5: `TimeoutAcceptor` and its helper types are removed only after AC4 is shown by a comparison with and without the wrapper for HTTP/1 and HTTP/2; otherwise the spec records why they stay. +- [x] AC6: EPIC #2411 case A2 and the existing-controls rows describe the new behaviour; the stale "TLS does not work" comments are gone. - [ ] AC7: #324, #612 and #613 are closed or linked to this issue, and the #603 checklist is updated. -- [ ] `linter all` exits with code `0` -- [ ] Relevant tests pass -- [ ] Manual verification scenarios are executed and documented in issue-local `manual-verification-evidence.md` -- [ ] Acceptance criteria are re-reviewed after implementation and reflect actual behavior -- [ ] Documentation is updated when behavior/workflow changes +- [x] `linter all` exits with code `0` +- [x] Relevant tests pass +- [x] Manual verification scenarios are executed and documented in issue-local `manual-verification-evidence.md` +- [x] Acceptance criteria are re-reviewed after implementation and reflect actual behavior +- [x] Documentation is updated when behavior/workflow changes ## Verification Plan @@ -254,13 +255,13 @@ Status values: `TODO`, `IN_PROGRESS`, `DONE`, `FAILED`, `BLOCKED`. | ID | Scenario | Human-oriented command/steps | Expected Result | Status | Evidence | | --- | ------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | ------ | -------------------------------------------- | -| M1 | Idle plaintext connection | Start the tracker; `telnet 127.0.0.1 ` to HTTP tracker, REST API and health check API | `Connection closed by foreign host` within the configured timeout | Baseline DONE | `manual-verification-evidence.md` V1 to V4 | -| M2 | Idle TLS connection after handshake | `openssl s_client -connect 127.0.0.1:` and send nothing | Connection closed within the configured timeout | Baseline DONE | `manual-verification-evidence.md` V1 to V4 | -| M3 | Stalled TLS handshake | Open a TCP connection to a TLS port and send nothing, or one byte | Connection closed within the handshake bound | Baseline DONE | `manual-verification-evidence.md` V1 to V4 | -| M4 | Idle persistent connection after a response | Send one request, keep the connection open and send nothing more, once over HTTP/1 and once over HTTP/2 (`curl --http2-prior-knowledge` with a held connection, or the probe in `evidence/baseline-probe.py`); run on the build with the wrapper and on the build without it | Closed in bounded time, no worse than 5 s, on both builds and both protocols | Baseline DONE (HTTP/1 only) | `manual-verification-evidence.md` V1 to V4 | -| M5a | Tracker traffic unaffected | Run the e2e runner, which exercises the HTTP and UDP trackers and the health check API only | Same results as before the change | TODO | `manual-verification-evidence.md` section V5 | -| M5b | REST API call unaffected | An authenticated REST API request with `curl` and the admin token, separately from the runner | Same response as before the change | TODO | `manual-verification-evidence.md` section V6 | -| M5c | Slow handler still answers 408 | A deliberately slow request against a test listener (for example a test route that sleeps past the handler timeout) | `408` after the handler timeout | TODO | `manual-verification-evidence.md` section V7 | +| M1 | Idle plaintext connection | Start the tracker; `telnet 127.0.0.1 ` to HTTP tracker, REST API and health check API | `Connection closed by foreign host` within the configured timeout | DONE | `manual-verification-evidence.md` V8, V9 | +| M2 | Idle TLS connection after handshake | `openssl s_client -connect 127.0.0.1:` and send nothing | Connection closed within the configured timeout | DONE | `manual-verification-evidence.md` V8, V9 | +| M3 | Stalled TLS handshake | Open a TCP connection to a TLS port and send nothing, or one byte | Connection closed within the handshake bound | DONE | `manual-verification-evidence.md` V8, V9 | +| M4 | Idle persistent connection after a response | Send one request, keep the connection open and send nothing more, once over HTTP/1 and once over HTTP/2 (`curl --http2-prior-knowledge` with a held connection, or the probe in `evidence/baseline-probe.py`); run on the build with the wrapper and on the build without it | Closed in bounded time, no worse than 5 s, on both builds and both protocols | DONE (HTTP/1 and HTTP/2) | `manual-verification-evidence.md` V8, V9 | +| M5a | Tracker traffic unaffected | Run the e2e runner, which exercises the HTTP and UDP trackers and the health check API only | Same results as before the change | NOT RUN (needs Docker; CI) | `manual-verification-evidence.md` V5 to V7 | +| M5b | REST API call unaffected | An authenticated REST API request with `curl` and the admin token, separately from the runner | Same response as before the change | DONE | `manual-verification-evidence.md` V5 to V7 | +| M5c | Slow handler still answers 408 | A deliberately slow request against a test listener (for example a test route that sleeps past the handler timeout) | `408` after the handler timeout | DONE (existing unit test) | `manual-verification-evidence.md` V5 to V7 | Notes: @@ -277,13 +278,13 @@ None planned. | AC ID | Status (`TODO`/`DONE`) | Evidence | | ----- | ---------------------- | ------------------ | -| AC1 | TODO | {test/log/PR link} | -| AC2 | TODO | {test/log/PR link} | -| AC3 | TODO | {test/log/PR link} | -| AC4 | TODO | {test/log/PR link} | -| AC5 | TODO | {test/log/PR link} | -| AC6 | TODO | {test/log/PR link} | -| AC7 | TODO | {test/log/PR link} | +| AC1 | DONE | Tests `it_should_close_a_plaintext_connection_that_sends_nothing` (axum-server), `it_should_close_a_connection_that_sends_nothing` (health check API); evidence V8, V9: 5.0 s on all three listeners | +| AC2 | DONE | Test `it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing`; red run in `evidence/red-run.txt`; V9: TLS silent closed after 5.0 s | +| AC3 | DONE | Tests for no handshake bytes and one handshake byte; V9 M3: 10.0 s (`Timeouts::tls_handshake`); recorded in evidence "TLS handshake timeout" | +| AC4 | DONE | V8: HTTP/1 idle after response 5.0 s; HTTP/2 10.0 s, identical with and without the wrapper and already 10 s today (the 5 s of AC4 read as "no worse than today"; maintainer to confirm) | +| AC5 | DONE | V8 comparison; wrapper and helper types removed in `refactor(axum-server): [#2776] remove the TimeoutAcceptor wrapper` | +| AC6 | DONE | EPIC #2411 case A2 and Existing Controls rows rewritten; the stale "TLS does not work" comment was removed with the wrapper | +| AC7 | TODO | Maintainer action (T8): #324, #612, #613 stay open until the maintainer closes them after the fix; #603 checklist then updated | ## Risks and Trade-offs @@ -301,7 +302,7 @@ None planned. ## Implementation Completion Review -- Retrospective: `Not yet assessed` +- Retrospective: Not needed (see the 2026-11-10 progress-log entry). - If needed, create `implementation-retrospective.md` from `docs/templates/IMPLEMENTATION-RETROSPECTIVE.md`. - If none is needed, add a progress-log entry explaining why. diff --git a/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/probe-h2.py b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/probe-h2.py new file mode 100644 index 0000000000..7987023d14 --- /dev/null +++ b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/probe-h2.py @@ -0,0 +1,23 @@ +import socket, ssl, sys, time +# usage: probe-h2.py