gateway: the fake ChatGPT socket counts a handshake before it reads the message

TestCodexSocketTooBigGoesOverHTTP was red on ubuntu CI at 8273325b0:
"2 posts, 0 sockets; want both turns over HTTP and one socket tried".
The fake counted a handshake after c.Read returned. A message over the
read limit is closed 1009 inside Read, so magpie can see the close and
finish both turns over HTTP before the fake's Read returns and counts.
It now counts right after Accept, which is what "sockets opened, a
refused message's too" says. The gateway is unchanged.

Run on mote (macOS 27), at this tree:
- With a 500ms sleep injected after the fake's Read: the old count is
  red 3 of 3 with CI's exact message; this one is ok -count=3.
- Without injection: go test -race -tags nogui -count=5 -run
  TestCodexSocket ./internal/gateway: ok. gofmt -l clean.
This commit is contained in:
yetone
2026-10-29 00:56:42 +08:00
parent 655f8dbd1c
commit b7da6cf932
+6 -3
View File
@@ -58,14 +58,17 @@ func (f *fakeSocketBackend) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
defer c.CloseNow()
// counted before the read: a message over the limit is closed
// 1009 inside Read, and the client can finish its turns over HTTP
// before Read returns
f.mu.Lock()
f.handshakes++
f.mu.Unlock()
c.SetReadLimit(-1)
if f.limit > 0 {
c.SetReadLimit(f.limit)
}
_, msg, err := c.Read(r.Context())
f.mu.Lock()
f.handshakes++
f.mu.Unlock()
if err != nil {
return
}