Skip to content

Handle fragmented HTTP requests on the metrics endpoint - #150

Merged
lance0 merged 2 commits into
masterfrom
fix/metrics-request-framing
Oct 16, 2026
Merged

lance0 merged 2 commits into
masterfrom
fix/metrics-request-framing

Conversation

@lance0

@lance0 lance0 commented Oct 16, 2026

Copy link
Copy Markdown
Owner

The metrics server treated the first TCP read as a complete HTTP request. If a request was split across packets, GET /metrics could return 405/404; incomplete requests could also be served before the headers had arrived.

Accumulate the request head through CRLF-CRLF, including delimiters split across reads, with an 8 KiB limit and one five-second deadline for the entire head. Validate the request line before routing; return 400 for incomplete/malformed requests and 431 for oversized headers. Keep the existing metrics/health paths, unsupported-method response, and connection-close behavior. No HTTP dependency is added.

Validation: a one-byte transport reproducibly returned 405 before the fix and returns 200 afterward. Tests cover fragmented request lines and terminators, larger/exact-limit headers, oversized/incomplete requests, unsupported methods, and a trickling client that must not extend the deadline. Existing real TCP endpoint tests pass. Also passed cargo build --locked, cargo test --locked, cargo clippy --locked --all-targets -- -D warnings, cargo fmt -- --check, cargo +1.88.0 check --all-targets --locked, and rustdoc with warnings denied.

lance0 and others added 2 commits October 15, 2026 22:39
A client that sends a valid request and never reads the response could
otherwise keep the connection task and its response buffer alive
indefinitely once the socket send buffer fills.
@lance0
lance0 marked this pull request as ready for review October 16, 2026 15:44
@lance0
lance0 merged commit e5b657e into master Oct 16, 2026
6 checks passed
@lance0
lance0 deleted the fix/metrics-request-framing branch October 16, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant