Skip to content

Commit

Permalink
test: fix concurrent map access in TestStatsFetcher
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.

Backport of #14496
  • Loading branch information
tgross committed Sep 8, 2022
1 parent 668a53f commit 7243532
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion nomad/stats_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ func TestStatsFetcher(t *testing.T) {
// from it.
func() {
s1.statsFetcher.inflight[string(s3.config.NodeID)] = struct{}{}
defer delete(s1.statsFetcher.inflight, string(s3.config.NodeID))

defer func() {
s1.statsFetcher.inflightLock.Lock()
delete(s1.statsFetcher.inflight, string(s3.config.NodeID))
s1.statsFetcher.inflightLock.Unlock()
}()

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

0 comments on commit 7243532

Please sign in to comment.