Files
magpie/docs
yetone 639a15c507 gateway: a chunked body is still arriving between two reads until a read meets its end (#4775)
Cause: bodyArriving (#4511) counted a body as still arriving between
two reads only when the request said its Content-Length. A chunked
body, which every encoded upload from an agent can be, was judged by
the read alone. When most's timer fired between two of its reads, the
request was answered 504 "without routing it to any provider", as a
hold of magpie's own, though its body was still coming. A decoder
spends its time between reads too: in the #4775 review, a stream of
empty gzip members got the 504 in 2 of 10 runs.

Change: waitedBody records that a read met its end or an error
(bodyEnded). A chunked body counts as arriving between reads until
then. A body read whole, an empty one, and one not yet begun (the wait
for body room) still count as magpie's hold. Every watched route reads
the body through request_bounds' io.ReadAll, so a read reaches EOF or
an error.

Tests:
- TestUnroutedBodyArrivingBetweenReads now expects a chunked body to
  count as arriving between reads, and not once its end is read.
- TestUnroutedChunkedBodyReadWholeHeld504 (identity, gzip and zstd,
  sent chunked) guards the other side: a hold after the whole body has
  been read is still 504.

Run, via mote-run (macOS arm64, Go 1.26.8, -tags nogui):
- go test -run TestUnrouted ./internal/gateway/: ok. 24 tests at this
  stage on 07b6834fe (wuuli's and Leng's patches).
- The full verification is in this series' last commit.

Broken by hand:
- No bodyEnded store: ChunkedBodyReadWholeHeld504 went red in all three
  encodings, answering 408 "its body was still arriving".
- The old `d <= 0` condition: BodyArrivingBetweenReads went red, with
  "a chunked body between two reads ... did not count as arriving".

Not tried: a real slow link or proxy, and the reporter's conversation.
2026-11-03 13:36:52 +08:00
..