Cause: with wuuli's upload credit, a request's charged time stands
still while its body earns at least as fast as it is read. When little
was left, checkMost re-armed most's timer at that sliver, and again
every time it fired, for as long as the body kept coming. In the #4775
review, a hold frozen 100µs short of unroutedMost was looked at 6731
times in a second.
Change: checkMost waits at least unroutedRecheck (1s, or an eighth of
unroutedMost when a test shortens it) before it looks again. A hold is
answered at most that much late. Masking, the 30s unknown-work guard,
the 60s socket idle deadline, the decoded cap and the trickle's 408
are unchanged.
Test: TestUnroutedMostRecheckIsNoSpin freezes a hold's charged time a
sliver short of unroutedMost and counts the timer's looks in a second.
It allows 30.
Run, via mote-run (macOS arm64, Go 1.26.8), at this tree before the
rebase (base affa979d5):
- gofmt -l: clean. go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...: all exit 0.
- go test -tags nogui -race -count=5 of the ten upload and body tests
(the patches' four, this series' five, TrickledBodyAnswered408): ok
(102.5s).
- go test -tags nogui -timeout 45m ./internal/gateway/...: one red
(771.9s), TestCodexPoolSaysTheClientsVersion. That is #4807 (another
test's Codex identity reaching it), fixed on main by 17f2387e1, which
this tree's base predated.
- After the rebase onto f3335dd1b (which brings 17f2387e1), at
698362aaf (this tree, before this message was amended):
go test -tags nogui -timeout 45m ./internal/gateway/...: ok (775.7s).
- go test -run TestUnrouted at each of the three commits: ok.
Broken by hand, each with its test (this series and the patches):
- Reset(left) without the floor: NoSpin went red (6731 looks).
- origin/main's unrouted.go with only the two names the tests need:
wuuli's TestUnroutedProgressingUploadOutlastsMost went red with 408
at 1s (identity, chunked, gzip, zstd), and so did
TestUnroutedUploadTimeIsBounded (5 of 6 cases). Leng's
TestUnroutedUploadAllowanceHasCeiling charged 11m against 3m.
TestUnroutedUploadCreditKeepsIdleDeadline passed, as a guard that
holds on main too should.
Not tried: a real slow link or proxy, the reporter's own conversation,
and running on Linux or Windows (vet only).
Thanks to wuuli (Xulin Wu) and lengjingxu (Leng on X, who reported it
again) for the patches this series builds on.
Co-authored-by: Xulin Wu <wuxulin@bytedance.com>
Co-authored-by: Leng <Lengjingxu@gmail.com>