diff --git a/Cargo.lock b/Cargo.lock index f7d56a4b8d..39f9fdec94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4989,12 +4989,14 @@ dependencies = [ "hyper", "rand 0.9.5", "reqwest", + "rustls", "serde", "serde_bencode", "serde_bytes", "socket2", "thiserror 2.0.21", "tokio", + "tokio-rustls", "tokio-util", "torrust-clock", "torrust-info-hash", @@ -5038,6 +5040,7 @@ dependencies = [ "tempfile", "thiserror 2.0.21", "tokio", + "tokio-rustls", "tokio-util", "torrust-clock", "torrust-info-hash", @@ -5072,17 +5075,14 @@ dependencies = [ "axum", "axum-server", "camino", - "futures-util", - "http-body", - "hyper", "hyper-util", - "pin-project-lite", + "rustls", "thiserror 2.0.21", "tokio", + "tokio-rustls", "tokio-util", "torrust-located-error", "torrust-tracker-configuration", - "tower", "tracing", ] diff --git a/Cargo.toml b/Cargo.toml index 88f24267a6..c552ccb173 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,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/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..91d71c3061 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,19 @@ +# Every Axum listener must be built through `torrust_tracker_axum_server::custom_axum_server`, which +# applies the connection timeouts (the first-request timeout closes silent connections). A listener +# built with these `axum-server` constructors directly keeps idle connections open forever, which +# lets a flood of silent connections exhaust the process's file descriptors (issue #2776, EPIC +# #2411 case A2). See `packages/axum-server/README.md`. +# +# Only the two constructors in `custom_axum_server.rs` call them, each with a documented `allow`. +# The decision is recorded in `docs/adrs/` (see the ADR on closing idle connections). +disallowed-methods = [ + { path = "axum_server::from_tcp", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::tls_rustls::from_tcp_rustls", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::bind", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::tls_rustls::bind_rustls", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::Server::bind", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::Server::from_listener", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::from_unix", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum_server::tls_rustls::from_unix_rustls", reason = "build listeners with torrust_tracker_axum_server::custom_axum_server so they get the connection timeouts (#2776)" }, + { path = "axum::serve", reason = "axum::serve has none of the connection timeouts; build listeners with torrust_tracker_axum_server::custom_axum_server (#2776)" }, +] diff --git a/docs/adrs/20261111095222_close_idle_connections_without_a_408_response.md b/docs/adrs/20261111095222_close_idle_connections_without_a_408_response.md new file mode 100644 index 0000000000..563e1c7d43 --- /dev/null +++ b/docs/adrs/20261111095222_close_idle_connections_without_a_408_response.md @@ -0,0 +1,84 @@ +--- +semantic-links: + skill-links: + - create-adr + related-artifacts: + - packages/axum-server/src/custom_axum_server.rs + - clippy.toml + - docs/adrs/20260830124000_place_adrs_by_decision_scope.md + - docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md + - .github/skills/dev/planning/create-adr/SKILL.md +--- + + + +# Close idle connections without a 408 response + +## Scope + +Repository-level. The decision is about protocol behaviour: whether the HTTP tracker, the REST API +and the health check API answer `408 Request Timeout` before closing an idle connection. The +listener constructors it describes live in `packages/axum-server`, but three server packages depend +on them, and the root `clippy.toml` that enforces their use binds every crate in the workspace. The +placement ADR (`20260830124000_place_adrs_by_decision_scope.md`) requires root placement for +protocol behaviour and shared configuration, even when one package implements it. + +## Description + +A connection that is opened and never sends a request holds a Tokio task and a file descriptor for +as long as the client keeps it open. Issue #2776 made every Axum listener (plaintext and TLS, HTTP +tracker, REST API and health check API) close such connections with `axum-server` 0.9's +`Server::first_request_timeout`, 5 s by default. + +When that timeout fires, `axum-server` returns from the connection task and drops the socket. The +client sees a plain close and no HTTP response. Some frameworks answer `408 Request Timeout` first +(Actix Web does, as the reproduction repository `josecelano/axum-server-timeout` shows). The +question is whether the tracker should do the same. + +## Agreement + +The tracker closes the connection silently and does not send `408 Request Timeout` for a +connection that has not sent a complete first request, an idle keep-alive connection, or a TLS +handshake that does not complete. + +Reasons: + +- A connection that sent nothing has no pending request to answer, so a bare close is valid HTTP + (RFC 9110 allows a server to send `408` but does not require it). +- It is the cheapest response under abuse: no write, no response buffer, and no bytes sent to a + client that already proved it will not send a request. +- It needs no custom code. A `408` would need a wrapper around the connection for plaintext, TLS + and HTTP/2, like the `TimeoutAcceptor` removed in #2776, or a new upstream feature. +- The tracker's clients are BitTorrent clients that make short announce and scrape requests. A + silent connection is almost certainly a scanner or an abuse attempt, not a client that needs an + explanation. + +A request that has arrived and whose handler is too slow still gets `408`, from the per-request +`TimeoutLayer` of the HTTP tracker and the REST API. That is a different timeout. + +### Alternatives Considered + +- **Send `408` then close.** Rejected: more server work in the situation that should be cheapest, + custom code for each transport, and the client's next write still fails with a broken pipe, as in + the Actix Web reproduction. + +### Consequences + +- Positive: no extra code to maintain; no response traffic for idle connections. +- Negative: clients and proxies see a reset or close instead of a `408`, and a reverse proxy may log + an upstream close. This is a known limitation. +- A client that answers the HTTP/2 keep-alive pings is not time-bounded by these timeouts; bounding it is the connection-limit work of EPIC #2411 case A1. +- Revisit this decision if real users report confusing logs behind a proxy. The preferred route is + an optional `408` in `axum-server` upstream, not custom tracker code. + +## Date + +2026-11-11 + +## References + +- Issue [#2776](https://github.com/torrust/torrust-tracker/issues/2776) and its spec, + `docs/issues/open/2776-2411-axum-server-0-9-timeouts/ISSUE.md` +- `axum-server` 0.9.0, `Server::first_request_timeout` +- Reproduction repository: +- RFC 9110, section 15.5.9 (`408 Request Timeout`) diff --git a/docs/adrs/index.md b/docs/adrs/index.md index effeb7f904..ff3fe2c840 100644 --- a/docs/adrs/index.md +++ b/docs/adrs/index.md @@ -61,6 +61,7 @@ supersession rules. | [20261104120915](20261104120915_stop_the_health_check_api_last_to_report_not_ready_during_shutdown.md) | 2026-11-04 | Stop the health check API last to report not ready during shutdown | A one-way `Readiness` state is marked before the components are cancelled, and the health check API stops after every other component so it answers `503` for the whole drain instead of refusing connections. | | [20261105132341](20261105132341_define_the_stats_and_metrics_endpoints_and_require_help_and_type_in_prometheus_output.md) | 2026-11-05 | Define the stats and metrics endpoints and require HELP and TYPE in Prometheus output | `/stats` is not deprecated and serves the aggregated statistics, `/metrics` serves the extendable labelled metrics, and every exported Prometheus text must carry `# HELP` and `# TYPE` (legacy `/stats` text aligned by #2734, amended 2026-11-06). | | [20261106102632](20261106102632_scope_the_cli_output_contract_and_keep_exit_codes_to_zero_one_two.md) | 2026-11-06 | Scope the CLI output contract and keep exit codes to 0, 1 and 2 | The contract covers operator binaries and the AI-agent and CI tools, not developer diagnostics; commands use only exit codes 0/1/2, and a distinct outcome is a `kind`: a result with exit 0 when it is the answer asked for, a stderr diagnostic with exit 1 when the command could not answer. | +| [20261111095222](20261111095222_close_idle_connections_without_a_408_response.md) | 2026-11-11 | Close idle connections without a 408 response | A connection that sends no complete first request is closed silently after the first-request timeout; no `408 Request Timeout` is sent. | ## ADR Lifecycle 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..5637ec698a 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 (cited by symbol, as the code stands after #2776): all three Axum server packages build their listener through `from_tcp_with_timeouts` or `from_tcp_rustls_with_timeouts` in `packages/axum-server/src/custom_axum_server.rs`, which call `add_timeouts` to set the first-request, header-read and HTTP/2 keep-alive timeouts from `Timeouts`; `from_tcp_rustls_with` also sets the TLS handshake timeout on the `RustlsAcceptor`; the health check API uses the same constructor (`start_with_cancellation` in `packages/axum-health-check-api-server/src/server.rs`). 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 | `add_timeouts` in `packages/axum-server/src/custom_axum_server.rs`: 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 | `add_timeouts` in `packages/axum-server/src/custom_axum_server.rs` | 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` ([ADR](../../../adrs/20261111095222_close_idle_connections_without_a_408_response.md)) | Not configurable, 5 s: `Timeouts::default` in `packages/axum-server/src/custom_axum_server.rs`; injectable in tests | A2 | +| HTTP header-read and HTTP/2 keep-alive timeouts | `add_timeouts` in `packages/axum-server/src/custom_axum_server.rs` | 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` in `packages/axum-server/src/custom_axum_server.rs` | A2 | +| TLS handshake timeout | `from_tcp_rustls_with` in `packages/axum-server/src/custom_axum_server.rs` | Closes a TLS connection that does not complete the handshake within 10 s (`RustlsAcceptor::handshake_timeout`) | Not configurable, 10 s: `Timeouts::default` in `packages/axum-server/src/custom_axum_server.rs` | 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..89175cf4f3 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-11 11:03" semantic-links: skill-links: - create-issue @@ -120,7 +120,7 @@ by the scenarios below. ## Architectural Decisions - Related ADRs: none known for timeouts. -- ADRs to create: none known. Create one if the tracker keeps a custom acceptor (or drops it) +- ADRs created: [Close idle connections without a 408 response](../../../adrs/20261111095222_close_idle_connections_without_a_408_response.md) (repository-level, 2026-11-11). Create another ADR if timeouts become configuration keys. with consequences worth recording, or if timeouts become configuration keys. ## Design and Ownership Review @@ -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,27 @@ 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 `refactor(axum-server): [#2776] remove the TimeoutAcceptor wrapper`. 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) +- 2026-11-10 21:40 UTC - Claude Code (Claude Sonnet 5.5) - Review round 1 (PR 2813: Copilot lite review and da2ce7, 13 findings). F1: reran the HTTP/2 probes with the wrapper; the wrapper does not shorten idle HTTP/2 (10.0 s, probable cause in the evidence), so the removal stands, but AC4 and AC5 are reopened (F5) for the maintainer's ruling and the unmeasured "already 10 s on develop" claim is dropped. Also: lockfile restored to develop's resolution for the two unrelated edges (F4), citations by symbol in the EPIC (F3), commit ids dropped (F2), red and green output with commands recorded (F6), HTTP/2 tests now require a response and a close no earlier than the injected timeout (F7), probe note replaced (F8), plus the Copilot suggestions (probe script trap, drop guard in the health check test, longer test timeouts, fixture README, doc note on `from_tcp_with_timeouts`). Audit: `docs/pr-reviews/pr-2813-review/PR-REVIEW.md`. +- 2026-11-11 08:53 UTC - Claude Code (Claude Sonnet 5.5) - AC4 and AC5 ticked. The maintainer's ACK on the pull request is taken as the ruling that an idle HTTP/2 connection closed after about 10 s is acceptable. The rationale below is the author's recommendation, not a quotation: the extra 5 s changes the cost of a descriptor-exhaustion attack little, and the real bound is a connection limit (EPIC #2411 case A1). AC4 reworded to match what ships. +- 2026-11-11 09:53 UTC - Claude Code (Claude Sonnet 5.5) - Added the ADR on closing idle connections without a `408` (silent close, revisit through an upstream `axum-server` feature if proxies report confusing logs). Merged `develop` into the branch to resolve conflicts with #2807 and #2812. +- 2026-11-11 10:29 UTC - Claude Code (Claude Sonnet 5.5) - Added the silent-connection test (plaintext and TLS) to the HTTP tracker and REST API packages, next to the existing health check API one. They fail when a listener bypasses the shared constructor: red run in `evidence/red-run-service-tests.txt`. Added the root `clippy.toml` `disallowed-methods` guard for the `axum-server` listener constructors, a documented `allow` in `custom_axum_server.rs`, comments at every call site, and switched the `token_aware_drain` example to the shared constructor. +- 2026-11-11 11:03 UTC - Claude Code (Claude Sonnet 5.5) - Review round 2 (da2ce7, findings F9 to F29 of their numbering): the ADR moved to `docs/adrs/` because the placement ADR puts protocol behaviour at the root; the README states the HTTP/2 condition (a client that answers pings is not time-bounded); the `signals.rs` test listener and the `token_aware_drain` example use the shared constructor, and `clippy.toml` also forbids `axum::serve` and the unix constructors; stamps use commit times, attributions to the maintainer are dropped and AC4 reads "no worse than with the wrapper". Audit: `docs/pr-reviews/pr-2813-review/PR-REVIEW.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 is closed in bounded time, no worse than with the wrapper (V8), measured on the replacement build: HTTP/1 after 5 s, HTTP/2 after about 10 s (5 s keep-alive interval plus 5 s ping reply wait). The maintainer accepted the HTTP/2 figure on 2026-11-11; a client that answers pings is not time-bounded (EPIC #2411 case A1). +- [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 +260,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 on both builds and both protocols: HTTP/1 after 5 s, HTTP/2 after about 10 s when pings go unanswered; no worse than with the wrapper (V8) | 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 +283,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 with and without the wrapper; maintainer accepted HTTP/2 about 10 s on 2026-11-11 | +| 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 +307,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/green-run.txt b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/green-run.txt new file mode 100644 index 0000000000..a53f984257 --- /dev/null +++ b/docs/issues/open/2776-2411-axum-server-0-9-timeouts/evidence/green-run.txt @@ -0,0 +1,37 @@ +# Green run on the final production code, 2026-11-11 UTC. Toolchain: rustc 1.99.1. +# $ cargo test -p torrust-tracker-axum-server -p torrust-tracker-axum-http-server -p torrust-tracker-axum-rest-api-server -p torrust-tracker-axum-health-check-api-server +# Filtered: the target headers, the silent-connection and idle tests, and every 'test result' line; other test names are omitted. + Running unittests src/lib.rs +test server::tests::it_should_close_a_connection_that_sends_nothing ... ok +test result: ok. 16 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.00s + Running tests/integration.rs +test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 3.06s + Running unittests src/lib.rs +test server::tests::it_should_close_a_plaintext_connection_that_sends_nothing ... ok +test server::tests::it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing ... ok +test result: ok. 51 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.09s + Running tests/integration.rs +test result: ok. 62 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.22s + Running unittests src/lib.rs +test server::tests::it_should_close_a_plaintext_connection_that_sends_nothing ... ok +test server::tests::it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing ... ok +test result: ok. 171 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 5.21s + Running tests/integration.rs +test result: ok. 58 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.31s + Running unittests src/lib.rs +test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s + Running tests/idle_connections.rs +test it_should_answer_a_request_sent_within_the_first_request_timeout ... ok +test it_should_close_a_plaintext_connection_that_sends_nothing ... ok +test it_should_close_an_idle_http1_connection_after_a_response_over_plaintext ... ok +test it_should_close_a_tls_connection_that_sends_one_handshake_byte_and_stalls ... ok +test it_should_close_a_tls_connection_that_never_sends_handshake_bytes ... ok +test it_should_close_an_idle_http1_connection_after_a_response_over_tls ... ok +test it_should_close_a_tls_connection_that_completes_the_handshake_and_sends_nothing ... 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 result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s 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..2781f5cdc4 --- /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