Make sure no loop variables are captured by func literals

This commit is contained in:
ionutboangiu
2023-07-14 11:29:19 -04:00
committed by Dan Christian Bogos
parent c7d226f8bb
commit ae67776d30
4 changed files with 8 additions and 8 deletions

View File

@@ -429,7 +429,7 @@ func (at *ActionTiming) Execute(successActions, failedActions chan *Action) (err
break
}
if successActions != nil {
go func() { successActions <- a }()
go func(action *Action) { successActions <- action }(a)
}
}
}

View File

@@ -95,11 +95,11 @@ func (t *Threshold) ProcessEvent(args *ArgsProcessEvent, dm *DataManager) (err e
}
if t.tPrfl.Async {
go func() {
go func(actID string) {
if errExec := at.Execute(nil, nil); errExec != nil {
utils.Logger.Warning(fmt.Sprintf("<ThresholdS> failed executing actions: %s, error: %s", actionSetID, errExec.Error()))
utils.Logger.Warning(fmt.Sprintf("<ThresholdS> failed executing actions: %s, error: %s", actID, errExec.Error()))
}
}()
}(actionSetID)
} else {
if errExec := at.Execute(nil, nil); errExec != nil {

View File

@@ -270,11 +270,11 @@ func BenchmarkGuardian(b *testing.B) {
// BenchmarkGuardIDs-8 1000000 8732 ns/op
func BenchmarkGuardIDs(b *testing.B) {
for n := 0; n < b.N; n++ {
go func() {
if refID := Guardian.GuardIDs("", 0, strconv.Itoa(n)); refID != "" {
go func(lockID int) {
if refID := Guardian.GuardIDs("", 0, strconv.Itoa(lockID)); refID != "" {
time.Sleep(time.Microsecond)
Guardian.UnguardIDs(refID)
}
}()
}(n)
}
}

View File

@@ -27,7 +27,7 @@ import (
"github.com/cgrates/cgrates/utils"
)
func Testv2ActionTriggerAsThreshold(t *testing.T) {
func TestV2ActionTriggerAsThreshold(t *testing.T) {
var filters []*engine.FilterRule
v2ATR := &v2ActionTrigger{
ID: "test2", // original csv tag