Skip to content

test(engine): the routes test server reads a request whole before answering - #1842

Merged
giswqs merged 1 commit into
mainfrom
fix/test-server-reads-body
Nov 12, 2026
Merged

giswqs merged 1 commit into
mainfrom
fix/test-server-reads-body

Conversation

@giswqs

@giswqs giswqs commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

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_out failed with io: An existing connection was forcibly closed by the remote host. (os error 10054) on windows-11-arm (run 43202320615) and Connection reset by peer (os error 54) on macOS (nightly run 43163420538). The test's serve_routes server 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_request helper reads the request head and then as much body as Content-Length says. It stops at 1 MiB and after a 5 s read timeout. serve_routes answers 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-engine lib tests pass locally, and fmt and clippy are clean. This PR is labelled ci:windows and ci:macos so the platforms that failed run the test.

Summary by CodeRabbit

  • Tests
    • Improved test-server handling of requests with declared bodies, allowing tests to wait for the complete request rather than relying on a single read.
    • Added bounded waiting and input-size limits to help tests handle incomplete, unusually large, or stalled requests more predictably.

…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.
@giswqs giswqs added ci:macos Run the macOS CI jobs on this pull request ci:windows Run the Windows CI jobs on this pull request labels Nov 12, 2026
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The test server now reads request data until it receives the headers and declared body, encounters a stream end or error, or reaches its size limit. serve_routes uses this helper instead of a single fixed-size read.

Changes: Test request reading

Layer / File(s) Summary
Collect requests before route matching
crates/engine/src/tests.rs
A private helper reads up to 1 MiB with a five-second timeout. It stops after receiving the headers and declared body, or when the stream ends or errors. serve_routes uses the accumulated request data. A comment about POST retry behavior was removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related issues

  • opengeos/RustGIS#1840 — The issue describes intermittent CI failures caused by serve_routes responding before reading the full request body. This change updates that request-reading path.

Suggested reviewers: pick2510, elpidioassinaturas

Merge Risk: Minimal · up to 92420

This change only makes a test server read the full request before answering, which should fix flaky Windows and macOS test failures. It does not alter library code or production behavior, and no merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the routes test server now reads a whole request before answering. It matches the changeset, which adds a read_request helper used by serve_routes in crates/engine/src…
Description check Passed The description follows the template's main sections. The Summary explains the cause, the fix, and the evidence. The Testing content appears in the Evidence paragraph, which reports the test runs, fmt…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the routes test server now reads a whole request before answering. It matches the changeset, which adds a read_request helper used by serve_routes in crates/engine/src/tests.rs. The title is 75 characters, which is slightly long but still clear.

Full details: Description check

Explanation

The description follows the template's main sections. The Summary explains the cause, the fix, and the evidence. The Testing content appears in the Evidence paragraph, which reports the test runs, fmt, and clippy results. The UI evidence section is covered by the 'No visible UI change' line, which the template allows for changes without visible UI. The Related issue section is not filled in. It links to CI runs and a nightly failure (#1776) in prose, but it does not use the 'Closes #' or 'Part of #' form that the template requests. This is a minor gap.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit reads each byte with care,
Till headers and the body are there.
A timeout waits; a limit stands,
The route then sees the gathered strands.
Hop, hop—the test server is prepared!

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 618c43bb-36fe-4791-96d3-fed322df5ec3
Commits

Reviewing files that changed from the base of the PR and between c8e424f and 92420cc.

Files selected for processing: 1

  • crates/engine/src/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

{
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));

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.

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.

Suggested change
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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 {

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.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Test-only and not a CI failure: the server only ever reads requests from our own client. Left for the release quality pass.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I reviewed the single changed file, crates/engine/src/tests.rs (+28/−5). It only touches a test helper, and the library code is unchanged. Prior review threads: none, so no concerns were skipped as already raised.

Bugs: none found. The new read_request loop behaves as intended on the paths I traced. It reads the head, then Content-Length bytes of body, and stops on EOF, error, the 1 MiB cap, or the 5 s timeout. Removing the stale "asked again as a GET" comment is accurate. The engine's POST→GET fallback (crates/engine/src/cmd/stac.rs, search) still exists, but this test no longer triggers it. Confidence: high.

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:

  • The end + 4 + body sum can overflow with a huge Content-Length, which panics in debug builds and kills the server thread. Inline comment posted with a saturating_add suggestion. Test-only, low impact. Confidence: high.
  • There is no regression test that writes the head and body in separate writes, so the fix is only proven by a temporary print and by CI on Windows and macOS. Inline comment posted as a suggestion for the release quality pass. Confidence: medium.
  • Nit, left for the release quality pass: the 40 connection count in stac_search_by_shape_says_what_it_leaves_out was sized for the retry and is now only an upper bound.

AGENTS.md: the change follows the rules. rustfmt.toml sets max_width = 140 and use_small_heuristics = "Max", so the long line is within format limits. No unwrap is added to non-test code (the file's existing unwraps are in test helpers). The PR body names the ci:windows and ci:macos labels, as AGENTS.md asks for platform-specific fixes.

Related, pre-existing (not in this diff, not posted): many other test servers in crates/engine/src/tests.rs still read a request once with a single 4 KiB read, for example around lines 12261, 15412, 20997, 21417, 21672, 22889, 23193 and 25232. Some of them answer POST bodies, so they have the same reset race. Moving them to read_request would be a follow-up. Confidence the race applies to each one: medium, since I did not check every route.

Change size

Compared: the whole PR against main (merge base c8e424f to PR head 92420cc).

Measure Value
Files changed 1 (added 0, modified 1, removed 0, renamed 0)
Size before 2.45 MB
Size after 2.46 MB
Total size change +944 B
Path Before After Change
crates/engine/src/tests.rs 2.45 MB 2.46 MB +944 B

@github-actions

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-1842/
Web app https://preview.rustgis.app/pr-1842/app/
Commit 92420cc

GitHub Pages takes a minute or two to publish a new commit.

@giswqs
giswqs merged commit 83d36a8 into main Nov 12, 2026
60 checks passed
@giswqs
giswqs deleted the fix/test-server-reads-body branch November 12, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:macos Run the macOS CI jobs on this pull request ci:windows Run the Windows CI jobs on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant