Expected Behavior
AppendSlices reads and mutates r.slices under the same mutex as every other reader method (MergeSlices, ClearSlices, loadAndSubmitTasks), so concurrent calls from the queue event loop (processNewRange → AppendSlices) and the reader's own event loop (loadAndSubmitTasks) should be data-race-free.
Actual Behavior
AppendSlices (service/history/queues/reader.go:279, current main) calls r.slices.Back() before acquiring the mutex, then locks only for the subsequent PushBack. Under concurrent load this races with any locked mutator of r.slices on container/list's internal pointers, confirmed with go test -race.
Steps to Reproduce
- Add a regression test to
service/history/queues/reader_test.go that runs a goroutine locking r and calling r.slices.MoveToBack in a loop, concurrently with a goroutine calling AppendSlices in a loop.
- Run:
go test -race -tags test_dep -count=1 -run 'TestReaderSuite/TestAppendSlices_RaceWithLockedMutation$' ./service/history/queues/
- Observe the race report:
AppendSlices → container/list.(*List).Back() racing with locked MoveToBack.
Specifications
- Version: current
main (ReaderImpl.AppendSlices, service/history/queues/reader.go)
- Platform: darwin/arm64,
go test -race -tags test_dep
Expected Behavior
AppendSlicesreads and mutatesr.slicesunder the same mutex as every other reader method (MergeSlices,ClearSlices,loadAndSubmitTasks), so concurrent calls from the queue event loop (processNewRange→AppendSlices) and the reader's own event loop (loadAndSubmitTasks) should be data-race-free.Actual Behavior
AppendSlices(service/history/queues/reader.go:279, currentmain) callsr.slices.Back()before acquiring the mutex, then locks only for the subsequentPushBack. Under concurrent load this races with any locked mutator ofr.slicesoncontainer/list's internal pointers, confirmed withgo test -race.Steps to Reproduce
service/history/queues/reader_test.gothat runs a goroutine lockingrand callingr.slices.MoveToBackin a loop, concurrently with a goroutine callingAppendSlicesin a loop.go test -race -tags test_dep -count=1 -run 'TestReaderSuite/TestAppendSlices_RaceWithLockedMutation$' ./service/history/queues/AppendSlices→container/list.(*List).Back()racing with lockedMoveToBack.Specifications
main(ReaderImpl.AppendSlices,service/history/queues/reader.go)go test -race -tags test_dep