record kept the last 40 calls by re-slicing the oldest off. The dropped
call stayed in the backing array, request and response captures and
all (up to 256 KiB each), until an append outgrew the array and copied
the ring to one about twice its size. So up to ~80 calls' bodies were
kept for a page that shows 40.
keepRecent now moves the last 39 down in place, clears the tail and
appends, so the array holds exactly the calls shown. Every reader of
s.recent copies what it needs under the lock, so moving the ring in
place changes nothing they see.
Measured, before (dee5c9d75, the `magpie web` gateway, 6 agents, 4746
requests over 60 min, average body 0.86 MB): the idle live heap was
52 MB in use. 18.7 MB of it was bytes.Buffer.String: 147 captures,
about 80 calls' worth, held by the ring. That share falls to the 40
calls shown. Allocations per request don't change (BenchmarkLargeRequest
55.37 MB/op before and after).
TestRecentRingKeepsNoDroppedBodies records 120 calls and watches each
call's bodies through weak pointers. Broken by hand (the re-slice put
back), it goes red: "46 calls dropped from the ring are still alive".
Run (darwin arm64, go1.26.8, sandbox HOME, load 40 to 90 from other
sessions' suites):
- go test ./... -count=1 -timeout 45m on the series' final tree at
ba319a758: exit 0, all 68 packages ok (gateway 1498s, agent 1633s).
- After the rebase onto b855cfee9 (two redact commits): go test
./internal/redact ./internal/gateway -count=1 -timeout 45m, both ok
(gateway 917s).
- go test -race -count=3 on the Held, ReadersOfAHeldBody, RecentRing,
RequestBody, CaptureRequest, folder, WorkPlace, WorkDir and Turn
tests: ok, after
TestReadersOfAHeldBodyParseItOnce's byte bound was skipped under
-race (the third commit says why); that test and
TestHeldFactsGoWithTheirBody then passed -count=30 with and without
-race.
- Each commit alone: go vet ./internal/gateway and gofmt -l clean.
- Final tree: gofmt -l clean; go vet ./... for darwin, GOOS=windows and
GOOS=linux -tags nogui, all exit 0.
Not tried: a second 60-minute soak after the series (the one before is
the "before" here; the "after" numbers are the benchmark's), the GUI
suite (nothing in it changed), Windows and Linux test runs (vet only).