Skip to content

Commit 43fe6ef

Browse files
authored
lint: fix nilaway warnings (part 3) (#3855)
1 parent 1d232f9 commit 43fe6ef

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

pkg/leakybucket/manager_run.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import (
1818

1919
var (
2020
serialized map[string]Leaky
21-
BucketPourCache map[string][]types.Event
21+
BucketPourCache map[string][]types.Event = make(map[string][]types.Event)
2222
BucketPourTrack bool
23+
bucketPourMu sync.Mutex
2324
)
2425

2526
/*
@@ -158,11 +159,11 @@ func PourItemToBucket(bucket *Leaky, holder BucketFactory, buckets *Buckets, par
158159
case bucket.In <- parsed:
159160
//holder.logger.Tracef("Successfully sent !")
160161
if BucketPourTrack {
161-
if _, ok := BucketPourCache[bucket.Name]; !ok {
162-
BucketPourCache[bucket.Name] = make([]types.Event, 0)
163-
}
164-
evt := deepcopy.Copy(*parsed)
165-
BucketPourCache[bucket.Name] = append(BucketPourCache[bucket.Name], evt.(types.Event))
162+
evt := deepcopy.Copy(*parsed).(types.Event)
163+
164+
bucketPourMu.Lock()
165+
BucketPourCache[bucket.Name] = append(BucketPourCache[bucket.Name], evt)
166+
bucketPourMu.Unlock()
166167
}
167168
sent = true
168169
continue
@@ -220,14 +221,11 @@ func PourItemToHolders(parsed types.Event, holders []BucketFactory, buckets *Buc
220221
var ok, condition, poured bool
221222

222223
if BucketPourTrack {
223-
if BucketPourCache == nil {
224-
BucketPourCache = make(map[string][]types.Event)
225-
}
226-
if _, ok = BucketPourCache["OK"]; !ok {
227-
BucketPourCache["OK"] = make([]types.Event, 0)
228-
}
229-
evt := deepcopy.Copy(parsed)
230-
BucketPourCache["OK"] = append(BucketPourCache["OK"], evt.(types.Event))
224+
evt := deepcopy.Copy(parsed).(types.Event)
225+
226+
bucketPourMu.Lock()
227+
BucketPourCache["OK"] = append(BucketPourCache["OK"], evt)
228+
bucketPourMu.Unlock()
231229
}
232230
//find the relevant holders (scenarios)
233231
for idx := range holders {

0 commit comments

Comments
 (0)