fix: cap scalers-cache reader at a per-reader budget derived from globalHTTPTimeout#7780
Conversation
|
Thank you for your contribution! 🙏 Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected. While you are waiting, make sure to:
Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient. Learn more about our contribution guide. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
if we conclude this is worth having, I will spin up a PR to charts and docs |
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable timeout for draining in-flight scaler cache readers during cache rebuild/close, preventing a single slow or stuck scaler read from stalling cache replacement indefinitely (follow-up to the reader-tracking fix added in #7737).
Changes:
- Add
KEDA_SCALERS_CACHE_READERS_DRAIN_TIMEOUT(default 5s) and plumb it from operator startup into the scale handler and scalers cache. - Update
ScalersCache.Close()to wait for readers with a bounded timeout before proceeding to close underlying scalers. - Add unit tests validating timeout and “disabled timeout” behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/util/env_resolver.go | Adds env var constant for the new drain-timeout configuration. |
| cmd/operator/main.go | Resolves the drain timeout from env (default 5s) and passes it into controllers/handlers. |
| pkg/scaling/scale_handler.go | Extends NewScaleHandler to carry the drain timeout and sets it on newly built caches. |
| pkg/scaling/cache/scalers_cache.go | Implements timeboxed waiting for active readers during cache close. |
| pkg/scaling/cache/scalers_cache_test.go | Adds tests covering timeout honoring and disabled-timeout behavior. |
| controllers/keda/scaledjob_controller.go | Plumbs the timeout into the ScaledJob controller’s scale handler. |
| controllers/keda/suite_test.go | Updates the scale handler constructor call in controller test setup. |
| CHANGELOG.md | Documents the new env var behavior in the unreleased changelog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'm struggling a bit with how this interacts with |
ef47d38 to
f337a15
Compare
for scalers that use keda's HTTP client, it would be effectively |
f337a15 to
09996f8
Compare
7c93d2f to
3de48c3
Compare
|
/run-e2e |
|
I'm wondering whether this could be smaller and simpler. Since the rebuild path already detaches the old cache via Would something along those lines be worth considering, or is there a case I'm missing that justifies the configurable approach? |
you bring a good point, there is a very little benefit for timeboxing async cache close when the cache is hotswapped (just a temporary goroutine running doesn't hurt that much).
I guess constant would be ok too, with these types of timeouts I usually default to configurability but the use case in configuring this particular timeout is also rather limited I am trying to explore another alternative, trying to see if I can refactor the synchronous path to also be asynchronous and then this timebox wouldn't be necessary at all |
Great that you're exploring this Jan! This would be a much cleaner outcome than a timebox, so it's well worth a try. |
3de48c3 to
265403e
Compare
265403e to
4a9d3ea
Compare
|
/run-e2e passed tests: 195failed tests: 2 |
Signed-off-by: Jan Wozniak <[email protected]>
globalHTTPTimeout
Signed-off-by: Jan Wozniak <[email protected]>
3de48c3 to
955cdf1
Compare
|
/run-e2e azure|scaling_strategies passed tests: 35failed tests: 1 |
|
/run-e2e azure_event_hub_blob_metadata_wi passed tests: 1failed tests: 0 |
…obalHTTPTimeout` (kedacore#7780) * fix: timebox scaler drain during cache rebuild Signed-off-by: Jan Wozniak <[email protected]> * cap scalers-cache reader budget Signed-off-by: Jan Wozniak <[email protected]> --------- Signed-off-by: Jan Wozniak <[email protected]> Signed-off-by: Yurii Shcherbak <[email protected]>
followup to #7737. The PR got merged before discussion regarding timeboxing the wait for active scalers during cache rebuild got concluded. I think #7737 is a great addition fixing real issue. My only concern was regarding the possible awry scaler taking too long to respond and affecting other scalers in the ScaledObject and their behavior.
Users will be able to set this through
globalHTTPTimeoutto control the drain mechanism to not exceed a configured timeout for this operation.Checklist
Relates to #7737
Relates to #7574