Commit Graph
2 Commits
Author SHA1 Message Date
yetone 970a86ff30 gateway: a vendor thinking for minutes is not pinged into GOAWAY too_many_pings
zdevoz (Discord, Windows, 0.1.3249): gemini-4-argon at effort high
through Antigravity waited ~235s for its first byte and then failed with
"http2: server sent GOAWAY and closed the connection; LastStreamID=3,
ErrCode=ENHANCE_YOUR_CALM, debug=\"too_many_pings\"". magpie logged a 502
and sent the whole turn again, so one turn took 421s.

Cause: the gateway's transports used Go's HTTP/2 health check
(netproxy.HTTP2Health, SendPingTimeout 10s). Go's client resets its
read-idle timer on every frame it reads, the ping's own ACK included
(h2_bundle.go readLoop / healthCheck), so a silent connection is pinged
every 10s for as long as the silence lasts, about 24 pings in four
minutes. Google's front end holds clients to gRPC's ping policy
(keepalive.md: a ping within MIN_RECV_PING_INTERVAL_WITHOUT_DATA, 5
minutes, of the last with no HEADERS or DATA sent between is a strike;
past MAX_PING_STRIKES, 2, the server sends GOAWAY ENHANCE_YOUR_CALM
"too_many_pings").

Fix: netproxy.CalmHTTP2 gives the gateway's vendor transports
(vendorTransport, so upstreamTransport and each Dispatch clone) an
HTTP/2 health check of magpie's own, on x/net/http2 with a ConnPool that
never dials (net/http dials through the proxy and hands the connection
over in TLSNextProto). The first ping of a silence still goes at
PingAfter (10s) and a lost one still drops the connection after
PingWait, in Go's words ("http2: client connection lost", which lostPing
reads), so #2843 and #4936 are found as fast as before. A silence starts
at the vendor's last HEADERS/DATA/CONTINUATION frame (read from the
frame headers as they come) or at the request handed to the connection.
After an answered ping the next waits PingAgain, 5 minutes, so a 4-minute
silence has one ping. A Dispatch clone gets its own pool (Clone copies
TLSNextProto, not RegisterProtocol), and t.CloseIdleConnections reaches
the calm pool through net/http's altProto lookup, so the proxy-move and
region drops (#4523, #5182) still close the connections.
uploadTransport stays on Go's HTTP/2 with no ping (#3909), and
http.DefaultTransport keeps HTTP2Health: its requests are short, and it
is cloned at 8 sites that would share one calm pool across proxies.

Retry after a GOAWAY: the retry the reporter saw is still made. With the
pings gone it should not be needed. When a GOAWAY does come, the
connection can't take a new request and the pool drops it, so the next
try dials anew (TestTryAfterGoawayDialsAnew).

Tests (no network):
- TestLongSilenceIsNotPingedIntoGoaway: a raw x/net Framer HTTP/2 vendor
  that enforces gRPC's ping policy (minimum gap scaled to 600ms, GOAWAY
  ENHANCE_YOUR_CALM too_many_pings past 2 strikes) and answers after a
  2.5s silence, reached through upstreamTransport with pings scaled to
  100ms/1s/1s.
- TestTryAfterGoawayDialsAnew.
- TestRequestOnAHoledConnectionFailsAtThePing now runs for HTTP2Health
  and CalmHTTP2, and the calm run must fail with "client connection lost".
- TestCalmFindsAPathDeadLaterInTheSilence: a path that dies after the
  first ping was answered is found at the PingAgain ping.
- TestCalmIdleConnectionsCloseAndClonesKeepTheirOwn.

Run (mote, Go 1.26.8):
- go vet -tags nogui ./internal/netproxy ./internal/gateway, plus
  GOOS=windows and GOOS=linux vet; gofmt -l clean.
- go test -race -count=1 ./internal/netproxy: ok.
- go test -count=1 -run
  "H2|HTTP2|Silent|Upload|Uplink|Region|Proxy|Goaway|LongSilence|Unsent|Replay|Fresh|LargeBody|Codex|Antigravity|CodeAssist"
  ./internal/gateway: ok (131s).
- win-run (xiaomi-gpu, Windows 11): go test ./internal/netproxy ok, and
  the gateway's Goaway/LongSilence/SilentHTTP2/Unsent/Upload/LargeBody
  tests ok.
- Again at the pushed head, rebased on 784113472: vet, gofmt,
  ./internal/netproxy and the gateway subset above (with TokenWall and
  Fallback, which the rebase brought in): ok.
- The full go test -timeout 45m ./... runs after the push under the
  suite lock; any red is filed as an issue with its output.

Broken by hand:
- vendorTransport back on HTTP2Health: TestLongSilenceIsNotPingedIntoGoaway
  red in 0.46s with the reporter's exact error: "http2: server sent GOAWAY
  and closed the connection; LastStreamID=1, ErrCode=ENHANCE_YOUR_CALM,
  debug=\"too_many_pings\"" (4 pings, 1 GOAWAY).
- watch with PingAgain = 1h: TestCalmFindsAPathDeadLaterInTheSilence red
  (context deadline at 20s).
- watch with PingAfter = 1h: TestRequestOnAHoledConnectionFailsAtThePing/
  CalmHTTP2 red (20s, the dead path not found).
- Dispatch not re-calming its clones: base's request went on the clone's
  connection, red.
- calmPool.CloseIdleConnections a no-op: the idle connection never
  closed, red.

Not tried: a real Antigravity or Google request (no real account was
used, and Google's exact tolerance is unknown: the report suggests about
22 pings at 10s). Not tried with a real proxy between. Go 1.27 moves
x/net's Transport onto net/http's (transport_wrap.go); ConnPool is still
honoured there, but this has not been run on it.

Reported-by: zdevoz (Discord)
2026-11-07 22:18:28 +08:00
ggbdpq ae3c2ec4e9 fix(netproxy): the health check pings a silent connection after 10s, not 20 (#4936)
What changed
The HTTP/2 health check is the only probe of a connection whose path has
died silently, so a turn in flight on such a connection waits for the
next one: with PingAfter at 20s a first try read EOF came ~20.5s after it
was written (Antigravity through a local proxy whose tunnel a NAT or a
relay had dropped, yetone/magpie#4936), and magpie's own retry served at
once on a new connection. PingAfter is 10s now: finding a dead path costs
at most half of what it did, and the margin a body under uploadBytes
needs on a slow uplink — the budget PingAfter+PingWait, a ping queued
behind the body and answered only after its last byte (#3909) — still
covers 64KB at about 3KB/s.

Run
go test -tags nogui -count=1 ./internal/netproxy (a new test walks a turn
onto a connection whose path dies under it and watches it fail at the
health check, then a retry serve on a connection of its own; a second
locks the sizing)
go test -tags nogui -count=1 ./internal/... — TestMothX,
TestProxyCheckSaysAProxyPassedBy and TestHostToldTheGatewayAddress are
red alone on the parent commit too; TestCodexPoolSaysTheClientsVersion is
a known full-suite flake, green alone
go vet, gofmt, GOOS=linux GOARCH=amd64 go build, GOOS=windows
GOARCH=amd64 go build, go build on darwin.

Reviewed and ported: every line read against origin/main 1b0340fdb.
Bodies of uploadBytes (64KB) and over go over HTTP/1.1, so the
PingAfter+PingWait budget, 30s down to 20s, still covers what HTTP/2
carries at ~3.2KB/s. On mote: TestPingAfterSizesTheDeadPathDiscovery is
red with netproxy.go put back to 1b0340fdb ("PingAfter 20s; want 10s"),
green with it. TestRequestOnAHoledConnectionFailsAtThePing builds its own
transport with scaled timings, so it passes on the old code too: it
documents Go's HTTP/2 health check on a dead tunnel, not this value.
On mote at this tree: go test -tags nogui -count=1 -timeout 45m
./internal/gateway/ ./internal/netproxy/: ok (gateway 1025.9s, netproxy
5.3s); go vet -tags nogui of both packages for darwin, GOOS=linux and
GOOS=windows: clean; gofmt -l: clean.
Not tried: the reporter's Clash/Mihomo route to Antigravity. This halves
the stall on a dead pooled connection (~21.5s to ~11.5s); it doesn't stop
the first try landing on it.

Generated-by: GLM-5.3-Flash (ZCode)
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
2026-11-05 18:31:16 +08:00