Skip to content

Commit

Permalink
test: fix concurrent map access in TestStatsFetcher (#14499)
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 authored Sep 8, 2022
1 parent f8d796f commit 5f2f6f5
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 5f2f6f5

Please sign in to comment.