Skip to content

Commit

Permalink
test: fix concurrent map access in TestStatsFetcher (#14496)
Browse files Browse the repository at this point in the history
The map of in-flight RPCs gets cleared by a goroutine in the test without first
locking it to make sure that it's not being accessed concurrently by the stats
fetcher itself. This can cause a panic in tests.
  • Loading branch information
tgross authored Sep 8, 2022
1 parent 22403d3 commit 3dab024
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nomad/stats_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func TestStatsFetcher(t *testing.T) {
// from it.
func() {
s1.statsFetcher.inflight[raft.ServerID(s3.config.NodeID)] = struct{}{}
defer delete(s1.statsFetcher.inflight, raft.ServerID(s3.config.NodeID))
defer func() {
s1.statsFetcher.inflightLock.Lock()
delete(s1.statsFetcher.inflight, raft.ServerID(s3.config.NodeID))
s1.statsFetcher.inflightLock.Unlock()
}()

ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
Expand Down

0 comments on commit 3dab024

Please sign in to comment.