Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
19 changes: 19 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -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 = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion][F29] The list covers only the axum-server constructors. axum::serve (axum 0.8.9 is in the lockfile) serves a router with none of these timeouts and is not forbidden; adding it closes the other route to an untimed listener. It is also worth checking against the axum-server 0.9 source that every listed path resolves and that no public constructor is missing, such as an associated Server::from_tcp if 0.9 still has one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid. Fixed in fix(axum-server): [#2776] address PR review round 2: axum::serve is forbidden, as are axum_server::from_unix and tls_rustls::from_unix_rustls. I checked the 0.9.2 source: the public constructors are bind, from_tcp, from_unix, Server::bind, Server::from_listener, bind_rustls, from_tcp_rustls and from_unix_rustls, and clippy accepts every path in the config.

{ 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)" },
]
Original file line number Diff line number Diff line change
@@ -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
---

<!-- skill-link: create-adr -->

# 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: <https://github.com/josecelano/axum-server-timeout>
- RFC 9110, section 15.5.9 (`408 Request Timeout`)
1 change: 1 addition & 0 deletions docs/adrs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading
Loading