Skip to content

Commit

Permalink
fix: prevent panic while refreshing a scaler cache (kedacore#4093)
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]>
  • Loading branch information
zroubalik committed Jan 16, 2023
1 parent 817d177 commit ddfaa6e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Here is an overview of all new **experimental** features:

### Fixes

- **General**: TODO ([#TODO](https://github.com/kedacore/keda/issues/TODO))
- **General**: Prevent a panic that might occur while refreshing a scaler cache ([#4092](https://github.com/kedacore/keda/issues/4092))

### 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 ddfaa6e

Please sign in to comment.