From 0976569bdceb6a73c917be54163e59a4c9122871 Mon Sep 17 00:00:00 2001 From: Onsi Fakhouri Date: Tue, 26 Apr 2022 10:23:51 -0600 Subject: [PATCH] guard against concurrent map writes in DeprecationTracker --- types/deprecation_support.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/deprecation_support.go b/types/deprecation_support.go index 79ca4593d..2948dfa0c 100644 --- a/types/deprecation_support.go +++ b/types/deprecation_support.go @@ -4,6 +4,7 @@ import ( "os" "strconv" "strings" + "sync" "unicode" "github.com/onsi/ginkgo/v2/formatter" @@ -84,11 +85,13 @@ func (d deprecations) Nodot() Deprecation { type DeprecationTracker struct { deprecations map[Deprecation][]CodeLocation + lock *sync.Mutex } func NewDeprecationTracker() *DeprecationTracker { return &DeprecationTracker{ deprecations: map[Deprecation][]CodeLocation{}, + lock: &sync.Mutex{}, } } @@ -102,6 +105,8 @@ func (d *DeprecationTracker) TrackDeprecation(deprecation Deprecation, cl ...Cod } } + d.lock.Lock() + defer d.lock.Unlock() if len(cl) == 1 { d.deprecations[deprecation] = append(d.deprecations[deprecation], cl[0]) } else { @@ -110,10 +115,14 @@ func (d *DeprecationTracker) TrackDeprecation(deprecation Deprecation, cl ...Cod } func (d *DeprecationTracker) DidTrackDeprecations() bool { + d.lock.Lock() + defer d.lock.Unlock() return len(d.deprecations) > 0 } func (d *DeprecationTracker) DeprecationsReport() string { + d.lock.Lock() + defer d.lock.Unlock() out := formatter.F("{{light-yellow}}You're using deprecated Ginkgo functionality:{{/}}\n") out += formatter.F("{{light-yellow}}============================================={{/}}\n") for deprecation, locations := range d.deprecations {