Repository navigation
test(engine): the routes test server reads a request whole before answering - #1842
Conversation
…wering serve_routes read one chunk and closed the socket with a POST body still unread. Windows and macOS reset such a connection, and when the reset arrived before the answer the client saw it in place of the answer: stac_search_by_shape_says_what_it_leaves_out failed with os error 10054 on windows-11-arm (CI on main) and os error 54 on macOS (nightly). The server now reads the head and the Content-Length body first, so each STAC search is answered on its POST.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| { | ||
| let head = String::from_utf8_lossy(&req[..end]).to_ascii_lowercase(); | ||
| let body = head.lines().find_map(|l| l.strip_prefix("content-length:")).and_then(|n| n.trim().parse::<usize>().ok()); | ||
| want = Some(end + 4 + body.unwrap_or(0)); |
There was a problem hiding this comment.
Nit (test-only, low impact): end + 4 + body can overflow. A Content-Length near usize::MAX parses fine, and the addition then panics in debug builds. That panic kills the server thread, and the client sees a hang or a reset instead of a clear failure. The 1 MiB cap below only applies to the loop condition, not to this sum. Saturating the sum avoids the overflow.
| want = Some(end + 4 + body.unwrap_or(0)); | |
| want = Some((end + 4).saturating_add(body.unwrap_or(0))); |
Confidence: high that it overflows. Impact is limited to a malformed test request.
There was a problem hiding this comment.
Test-only and not a CI failure: the server only ever reads requests from our own client. Left for the release quality pass.
| /// A request read whole: its head and as much body as its `Content-Length` says. A server that | ||
| /// answers and closes with part of the request unread has its connection reset on Windows and | ||
| /// macOS, and the client sees the reset in place of the answer. | ||
| fn read_request(s: &mut std::net::TcpStream) -> String { |
There was a problem hiding this comment.
The fix has no regression test. Its evidence is a temporary print in the server, and the existing test only catches the reset on Windows and macOS CI, where it is intermittent. A small test would pin the behaviour on every platform. Connect a client, write the request head, sleep briefly, then write a body of a few KB in a second write. Assert that read_request returns the head and the whole body, and that a request with no Content-Length returns after its head. This is a suggestion, not a blocker. It is an extra test for code that already works, so it can wait for the release quality pass.
Confidence: medium. The current change is correct as far as I can tell by reading.
There was a problem hiding this comment.
Test-only and not a CI failure: the server only ever reads requests from our own client. Left for the release quality pass.
Code reviewI reviewed the single changed file, Bugs: none found. The new Security: none in scope. This is a loopback test server. Performance: none. The loop costs nothing once the body is read, and GET requests return right after the head. Quality:
AGENTS.md: the change follows the rules. Related, pre-existing (not in this diff, not posted): many other test servers in Change sizeCompared: the whole PR against main (merge base c8e424f to PR head 92420cc).
|
📖 Docs preview
GitHub Pages takes a minute or two to publish a new commit. |
Fixes the red CI on main (c8e424f,
Test (windows-11-arm)) and the macOS failure in today's nightly (#1776).Cause.
stac_search_by_shape_says_what_it_leaves_outfailed withio: An existing connection was forcibly closed by the remote host. (os error 10054)on windows-11-arm (run 43202320615) andConnection reset by peer (os error 54)on macOS (nightly run 43163420538). The test'sserve_routesserver read one 4 KiB chunk, answered, and closed the socket while the POST body (the search shape) was still unread. Closing a socket with unread data sends a reset. On Windows and macOS the reset sometimes reached the client before the answer did, so the POST failed. Its GET fallback then went to the same server, and the test surfaced the POST's error. The test comment had already noted the effect ("a POST answered before its body is read is asked again as a GET").Fix. A
read_requesthelper reads the request head and then as much body asContent-Lengthsays. It stops at 1 MiB and after a 5 s read timeout.serve_routesanswers only after that read. The stale comment is removed. Library code is unchanged.Evidence. With a temporary print in the server, every search in the test is answered on its POST, with no GET retry. One body (3443 bytes) arrived in several segments. All 1352
rustgis-enginelib tests pass locally, and fmt and clippy are clean. This PR is labelledci:windowsandci:macosso the platforms that failed run the test.Summary by CodeRabbit