Skip to content

Commit 9bc3f66

Browse files
authored
fix: prevent panic while refreshing a scaler cache (#4093) (#4119)
Signed-off-by: Zbynek Roubalik <[email protected]> Signed-off-by: Zbynek Roubalik <[email protected]> Signed-off-by: Zbynek Roubalik <[email protected]>
1 parent e68b819 commit 9bc3f66

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Here is an overview of all new **experimental** features:
6262

6363
- **General**: Prevent a panic that might occur while refreshing a scaler cache ([#4092](https://github.com/kedacore/keda/issues/4092))
6464
- **Azure Service Bus Scaler:** Use correct auth flows with pod identity ([#4026](https://github.com/kedacore/keda/issues/4026))
65+
- **Prometheus Metrics**: Fix exposed metric from `keda_scaled_errors` to `keda_scaled_object_errors` ([#4037](https://github.com/kedacore/keda/issues/4037))
6566

6667
### Deprecations
6768

pkg/scaling/cache/scalers_cache.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,20 @@ func (c *ScalersCache) refreshScaler(ctx context.Context, id int) (scalers.Scale
235235
}
236236

237237
sb := c.Scalers[id]
238+
defer sb.Scaler.Close(ctx)
238239
ns, sConfig, err := sb.Factory()
239240
if err != nil {
240241
return nil, err
241242
}
242243

244+
if id < 0 || id >= len(c.Scalers) {
245+
return nil, fmt.Errorf("scaler with id %d not found. Len = %d", id, len(c.Scalers))
246+
}
243247
c.Scalers[id] = ScalerBuilder{
244248
Scaler: ns,
245249
ScalerConfig: *sConfig,
246250
Factory: sb.Factory,
247251
}
248-
sb.Scaler.Close(ctx)
249252

250253
return ns, nil
251254
}

0 commit comments

Comments
 (0)