Skip to content

Commit

Permalink
fix: prevent panic while refreshing a scaler cache (#4093) (#4119)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <[email protected]>

Signed-off-by: Zbynek Roubalik <[email protected]>

Signed-off-by: Zbynek Roubalik <[email protected]>
  • Loading branch information
zroubalik authored Jan 16, 2023
1 parent e68b819 commit 9bc3f66
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Here is an overview of all new **experimental** features:

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

### Deprecations

Expand Down
5 changes: 4 additions & 1 deletion pkg/scaling/cache/scalers_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,20 @@ func (c *ScalersCache) refreshScaler(ctx context.Context, id int) (scalers.Scale
}

sb := c.Scalers[id]
defer sb.Scaler.Close(ctx)
ns, sConfig, err := sb.Factory()
if err != nil {
return nil, err
}

if id < 0 || id >= len(c.Scalers) {
return nil, fmt.Errorf("scaler with id %d not found. Len = %d", id, len(c.Scalers))
}
c.Scalers[id] = ScalerBuilder{
Scaler: ns,
ScalerConfig: *sConfig,
Factory: sb.Factory,
}
sb.Scaler.Close(ctx)

return ns, nil
}
Expand Down

0 comments on commit 9bc3f66

Please sign in to comment.