fix: stop pooling request waiters — a borrow safe only by fragile ordering #9
No reviewers
Labels
No labels
code-review
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
norobo/webstream!9
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/request-waiter-pool"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Scope
Follow-up to PR #8 comment 758, which claimed a pooled-
wireWriterdata race in the client. This PR corrects that claim and fixes the one genuine fragility the investigation surfaced.This PR stacks on
feat/mesh-replication-command-log(PR #8).The correction
Comment 758 said the client's pooled
wireWriter"can hand the same writer to concurrent requests on different streams", corrupting frames. Testing that hypothesis disproved it:sync.Poolhandoff is exclusive: instrumentinggetWaiter/borrow lifetimes showed no waiter was ever handed to two live requests across thousands of borrows.ack.Seq == valueis invalid under concurrency because the server assigns sequence numbers in arrival order —publish 350 answered with seq 0means 350's request arrived first, not that responses crossed.rpcStreamare false positives of the pure-Go detector (the only detector available here — no CGO): it flagsr.pending[requestID] = waiterandr.pendingLock.Unlock()— both inside the lock's own critical section — and even pairs accesses to different heap addresses as racing. The same detector reports(*Server).acquire'srs.refs++racing, which is provably unders.lock.The fix
The
requestWaiterpool is a real fragility of the same borrow class, and it is the one worth removing:getWaitermutates the pooled struct's fields (kind,ch) with no lock.deliverreadswaiter.kindand sends onwaiter.chunderpendingLock).delivernotifies underpendingLock, and every pool return follows the pending-map removal. Reorder either and the borrow goes stale.The
wireWriterpool is kept: its borrow is strictly synchronous insiderequest(the write completes before the put), so it cannot hand the same buffer to two live borrowers.Test
TestRPCStreamConcurrentRequests: 8 goroutines × 50 publishes on the control stream while a consumer loops on its own pull stream (pulls + acks in flight on a secondrpcStream), asserting the real identity contract — every publish answered exactly once, response seqs exactly0..N-1once each. This is the regression test a waiter mixup would break (a lost or duplicated response shows up as a missing or duplicated seq).Verification
go build ./...,go vet ./...,gofmt -l .clean.go test ./...clean ×4; stress test 10/10.racedetectoron the mesh/replication/conn subset: clean (0 reports).golangci-lint run --fix=false: 81 issues — identical tomain's baseline; nothing in the edited files.go.mod/go.sumunchanged.