From fafce65455eec68915d6118dc27363c1692e4db1 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 28 Oct 2026 08:23:31 +0800 Subject: [PATCH] gateway: the facts' allocation bound is checked when not under -race (#3956) TestChatAndMessagesFactsLeaveTheHistory (9a888323a, #3472) was red every time under -race on ubuntu and macOS CI from ec6c2de52 on; earlier runs hid it, as their Test step was red and the Race step never ran. regexp keeps its backtracker in a sync.Pool, and under -race sync.Pool lets a quarter of what is put in it go, so userSaid's matches over a long conversation made new ones: a memory profile of readFacts alone shows regexp.(*bitState).reset at 13.61 MB over five reads under -race, 0.07 MB without. The bound is now skipped under raceOn, as its sibling at parse_memo_test.go:71 already is for workDirIn's regexps. Run at origin/main 833f51adc + this change, on mote: - go test -race -run TestChatAndMessagesFacts -count=3 ./internal/gateway/: ok, 3 of 3. Before the change: FAIL 3 of 3 (chat 3851848 bytes against a parse's 4524408). - go test -run TestChatAndMessagesFacts -count=3 ./internal/gateway/: ok (facts 980072 bytes against 4503336, the bound unchanged). - go vet ./internal/gateway/: ok. gofmt -l: none. Not run: the full gateway race shards; CI runs them. --- internal/gateway/parse_memo_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/gateway/parse_memo_test.go b/internal/gateway/parse_memo_test.go index b0deda26f..3dd3390ea 100644 --- a/internal/gateway/parse_memo_test.go +++ b/internal/gateway/parse_memo_test.go @@ -242,7 +242,10 @@ func TestChatAndMessagesFactsLeaveTheHistory(t *testing.T) { facts := allocated(func() { readFacts(proto, body) }) parsed := allocated(func() { _, _ = parse(proto, body) }) t.Logf("%s: %d-byte body, facts allocated %d bytes, the whole parse %d", proto, len(body), facts, parsed) - if facts*3 > parsed { + // Under -race, sync.Pool drops a quarter of what is put in it, and + // userSaid's regexps take their backtrackers from one, so a long + // conversation's facts make ~2.7 MB more of them (#3956). + if !raceOn && facts*3 > parsed { t.Errorf("%s: facts allocated %d bytes, a third or more of the whole parse's %d", proto, facts, parsed) } }