From 554a04e83b0951cb1b5ecf528e64e429b3da60e0 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Sun, 27 Apr 2025 19:44:55 +0200 Subject: [PATCH 1/3] fix: ScalerCache holds the lock before operate the scalers Signed-off-by: Jorge Turrado --- pkg/scaling/cache/scalers_cache.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/scaling/cache/scalers_cache.go b/pkg/scaling/cache/scalers_cache.go index 332a419b504..27bebc9f73e 100644 --- a/pkg/scaling/cache/scalers_cache.go +++ b/pkg/scaling/cache/scalers_cache.go @@ -67,12 +67,13 @@ func (c *ScalersCache) GetScalers() ([]scalers.Scaler, []scalersconfig.ScalerCon // getScalerBuilder returns a ScalerBuilder stored in the cache func (c *ScalersCache) getScalerBuilder(index int) (ScalerBuilder, error) { + c.mutex.RLock() + defer c.mutex.RUnlock() + if index < 0 || index >= len(c.Scalers) { return ScalerBuilder{}, fmt.Errorf("scaler with id %d not found. Len = %d", index, len(c.Scalers)) } - c.mutex.RLock() - defer c.mutex.RUnlock() return c.Scalers[index], nil } From 48f92a121cc7baf1bde81cca8fc9d18663f5d190 Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Sun, 27 Apr 2025 19:54:27 +0200 Subject: [PATCH 2/3] add missing lock Signed-off-by: Jorge Turrado --- pkg/scaling/cache/scalers_cache.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/scaling/cache/scalers_cache.go b/pkg/scaling/cache/scalers_cache.go index 27bebc9f73e..6e59f73975f 100644 --- a/pkg/scaling/cache/scalers_cache.go +++ b/pkg/scaling/cache/scalers_cache.go @@ -79,6 +79,8 @@ func (c *ScalersCache) getScalerBuilder(index int) (ScalerBuilder, error) { // GetPushScalers returns array of push scalers stored in the cache func (c *ScalersCache) GetPushScalers() []scalers.PushScaler { + c.mutex.RLock() + defer c.mutex.RUnlock() var result []scalers.PushScaler for _, s := range c.Scalers { if ps, ok := s.Scaler.(scalers.PushScaler); ok { From 33cf62cacd75b756db8e9819d46f44f20145e7ea Mon Sep 17 00:00:00 2001 From: Jorge Turrado Date: Mon, 28 Apr 2025 12:39:26 +0200 Subject: [PATCH 3/3] update changelog Signed-off-by: Jorge Turrado --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2924d057d34..578df1fdb18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio ### Fixes - **General**: Admission Webhook blocks ScaledObject without metricType with fallback ([#6696](https://github.com/kedacore/keda/issues/6696)) +- **General**: ScalerCache gets the lock before operate the scalers to prevent panics ([#6739](https://github.com/kedacore/keda/pull/6739)) - **AWS SQS Queue Scaler**: Fix AWS SQS Queue queueURLFromEnv not working ([#6712](https://github.com/kedacore/keda/issues/6712)) - **Temporal Scaler**: Fix Temporal Scaler does not work properly with API Key authentication against Temporal Cloud as TLS is not enabled on the client ([#6703](https://github.com/kedacore/keda/issues/6703))