Files
magpie/docs
yetone 05ed578bdc gateway: a large body whose h2 ping was lost goes again unpinged (#3909)
yxd-ym, on a 2-10KB/s uplink: every large turn to a Google upstream
(Antigravity, Vertex, AI Studio) failed with "http2: client connection
lost" after 35-45s while its body was still uploading, and the group's
failover uploaded the same ~680KB again to every member. A small turn on
the same uplink was answered in 14s.

Cause (skygunner's diagnosis): the vendor transport's HTTP/2 health check
(netproxy.HTTP2Health, #2843) pings a connection with no frame received
for 20s and drops it when no answer comes in 10s. The ping is written
behind the body's own DATA, so on a slow uplink its answer can only come
after the last byte, and the check closed a working connection.

skygunner's branch (8eaf63866) sent every body of 64KB or more, or of no
stated length, to a transport without the ping. That is most agent
traffic, and it takes #2843's protection away from it: a silent
connection whose kernel takes a body that fits the send buffer then
waits the 10-minute header wait (TestLargeBodyOnSilentConnectionIsSentAgain
below hangs to its 10s bound on that branch).

The change keeps the ping on every request by default. A large body
(uploading) whose try fails with Go's lost-ping error (lostPing,
closeForLostPing's "http2: client connection lost") is sent once more,
through GetBody (provider.SetBody keeps it until LetGo), through
uploadTransport: a new connection, no ping, given up on when a write
moves no bytes for a minute (WriteByteTimeout); the response header wait
still ends a vendor that never answers. For 30 minutes after (slowFor,
drawsApart.slow, per transport), large bodies go there at once, so a slow
uplink loses one try per half hour, not one per turn. A connection that
really was dead costs nothing more: the retry dials a new one either way.
Small bodies and drawings are unchanged.

Co-authored-by: vincent <vincent@users.noreply.github.com>
Reported-by: yxd-ym

What was run, on mote at origin/main ea53eb126 + this:
- gofmt -l internal/gateway: nothing. go vet ./internal/gateway/
  ./internal/netproxy/, and GOOS=linux / GOOS=windows go vet
  ./internal/gateway/: nothing.
- TestUploadStillUnderwayIsNotCutByHealthPing (skygunner's: 262212 bytes
  paced at 64KB/s, ping after 200ms, dropped 300ms later),
  TestSlowUplinkSkipsTheLostTry (new: the first large body reaches the
  vendor twice, the second once, body given through provider.SetBody),
  TestLargeBodyOnSilentConnectionIsSentAgain (new: 128KB body after the
  path went silent is answered on a second connection),
  TestSilentHTTP2ConnectionIsDropped, TestGroupMovesOnFromSilentHTTP2Connection:
  -race -count=5 all PASS (80s); -count=3 without -race PASS.
- Broken by hand:
  - skygunner's transport alone: TestSlowUplinkSkipsTheLostTry FAIL ("saw
    1 tries of the first body, want 2"), TestLargeBodyOnSilentConnection
    IsSentAgain FAIL (context deadline exceeded at 10.01s).
  - the retry removed: TestUploadStillUnderwayIsNotCutByHealthPing FAIL
    in 0.57s ("http2: client connection lost", vendor "client
    disconnected"), TestLargeBodyOnSilentConnectionIsSentAgain FAIL
    (client connection lost).
- go test ./internal/gateway/ ./internal/netproxy/ ./internal/provider/
  -count=1 -timeout 45m: ok
  (gateway 546s, netproxy 3.7s, provider 118s).

Rebased onto f02d92c7b (no change to these files but a doc line
elsewhere in gateway-routing.md): gofmt, go vet (darwin, linux,
windows) ./internal/gateway/, and the five tests above with
TestPromptText* and *Unmasked* -count=2: ok (32s).

Not tried: the reporter's uplink and a real Google upstream; the path is
a paced local one.
2026-10-28 15:22:31 +08:00
..