diff --git a/CHANGELOG.md b/CHANGELOG.md index baab66e75a4..36eb2bbc351 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ ### Other - Adding OpenStack Swift scaler end-to-end tests ([#1522](https://github.com/kedacore/keda/pull/1522)) +- Pass deepCopy objects to the polling goroutines ([#1812](https://github.com/kedacore/keda/pull/1812)) ## v2.2.0 diff --git a/pkg/scaling/scale_handler.go b/pkg/scaling/scale_handler.go index 1adc62e18e6..0203fd7b3ff 100644 --- a/pkg/scaling/scale_handler.go +++ b/pkg/scaling/scale_handler.go @@ -101,8 +101,16 @@ func (h *scaleHandler) HandleScalableObject(scalableObject interface{}) error { // a mutex is used to synchronize scale requests per scalableObject scalingMutex := &sync.Mutex{} - go h.startPushScalers(ctx, withTriggers, scalableObject, scalingMutex) - go h.startScaleLoop(ctx, withTriggers, scalableObject, scalingMutex) + + // passing deep copy of ScaledObject/ScaledJob to the scaleLoop go routines, it's a precaution to not have global objects shared between threads + switch obj := scalableObject.(type) { + case *kedav1alpha1.ScaledObject: + go h.startPushScalers(ctx, withTriggers, obj.DeepCopy(), scalingMutex) + go h.startScaleLoop(ctx, withTriggers, obj.DeepCopy(), scalingMutex) + case *kedav1alpha1.ScaledJob: + go h.startPushScalers(ctx, withTriggers, obj.DeepCopy(), scalingMutex) + go h.startScaleLoop(ctx, withTriggers, obj.DeepCopy(), scalingMutex) + } return nil }