fix(aws): close idle HTTP connections in AWS scaler Close() methods#7740
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. |
|
/run-e2e aws* |
|
Fwiw #3387 is about azure and I had a similar issue with the aws ones - this is addressing the same problem with aws sdk - if you want me to file a new bug about the aws leak I can do so |
Yes, that seems fine to me. You could then optionally link to the similar issue in your issue. |
|
WDYT? Could we use |
|
Good call... I switched to |
|
@rickbrouwer i don't think there is anything left to do here. |
|
LGTM. Thanks for iterating on this. Maybe only one thing you also mentioned:
Can you create this separate issue and link it in the CHANGELOG and description? |
|
will do so - tyvm - standby |
|
/run-e2e aws* |
|
/run-e2e aws* passed tests: 26failed tests: 0 |
There was a problem hiding this comment.
Pull request overview
This PR addresses a resource leak in KEDA’s AWS SDK-based scalers by ensuring their underlying HTTP connection pools are deterministically cleaned up when a scaler is closed, preventing long-lived TCP connections from accumulating in the operator.
Changes:
- Add an explicit
*http.Clientto AWS scalers (SQS, Kinesis, DynamoDB, DynamoDB Streams, CloudWatch) and inject it viaoptions.HTTPClient. - Call
httpClient.CloseIdleConnections()from each scaler’sClose()method. - Add/adjust unit tests to cover the new
Close()behavior and update the changelog entry.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/scalers/aws_sqs_queue_scaler.go | Adds per-scaler HTTP client, injects into AWS SQS client, closes idle connections on Close() |
| pkg/scalers/aws_sqs_queue_scaler_test.go | Updates struct literals and adds Close() HTTP cleanup tests (one added test is misleading) |
| pkg/scalers/aws_kinesis_stream_scaler.go | Adds per-scaler HTTP client, injects into AWS Kinesis client, closes idle connections on Close() |
| pkg/scalers/aws_kinesis_stream_scaler_test.go | Updates struct literals and adds Close() HTTP cleanup test |
| pkg/scalers/aws_dynamodb_streams_scaler.go | Adds per-scaler HTTP client, injects into DynamoDB + Streams clients, closes idle connections on Close() |
| pkg/scalers/aws_dynamodb_streams_scaler_test.go | Updates struct literals and adds Close() HTTP cleanup test |
| pkg/scalers/aws_dynamodb_scaler.go | Adds per-scaler HTTP client, injects into DynamoDB client, closes idle connections on Close() |
| pkg/scalers/aws_dynamodb_scaler_test.go | Updates struct literals and adds Close() HTTP cleanup test |
| pkg/scalers/aws_cloudwatch_scaler.go | Adds per-scaler HTTP client, injects into CloudWatch client, closes idle connections on Close() |
| pkg/scalers/aws_cloudwatch_scaler_test.go | Updates struct literals and adds Close() HTTP cleanup test |
| CHANGELOG.md | Documents the fix for AWS scaler TCP connection leak |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
30e5e65 to
dbad5ca
Compare
The AWS SDK-based scalers (SQS, Kinesis, DynamoDB, DynamoDB Streams, CloudWatch) never closed their underlying HTTP transport connections when Close() was called. ClearAwsConfig() only removes credential cache entries but does not shut down the HTTP client. This causes TCP connections to accumulate indefinitely, eventually exhausting file descriptors and causing the operator to lose connectivity. Store an explicit *http.Client on each scaler struct, inject it into the AWS SDK client via options.HTTPClient, and call CloseIdleConnections() in Close(). This matches the pattern established in PR kedacore#5293 for non-AWS scalers. Signed-off-by: Raymond Barbiero <[email protected]>
|
look - AI reviews here are imho bad/annoying now - i'm not making any more changes to this code. either take it or leave it but i'm done fighting copilot. |
|
/run-e2e aws* |
|
/run-e2e aws* passed tests: 26failed tests: 0 |
fair call, from my experience, even the best LLM models report something about 20% - 40% valid reviews and when retriggered on updates, past 5th iteration this ratio drops to 0 |
|
I completely agree. It indeed looks like the LLM always wants to give something back, no matter how far-fetched, even if the code is fine. That’s why it’s good to decide at some point that it’s best to just let it go :) |
…edacore#7740) The AWS SDK-based scalers (SQS, Kinesis, DynamoDB, DynamoDB Streams, CloudWatch) never closed their underlying HTTP transport connections when Close() was called. ClearAwsConfig() only removes credential cache entries but does not shut down the HTTP client. This causes TCP connections to accumulate indefinitely, eventually exhausting file descriptors and causing the operator to lose connectivity. Store an explicit *http.Client on each scaler struct, inject it into the AWS SDK client via options.HTTPClient, and call CloseIdleConnections() in Close(). This matches the pattern established in PR kedacore#5293 for non-AWS scalers. Signed-off-by: Raymond Barbiero <[email protected]> Co-authored-by: Rick Brouwer <[email protected]> Signed-off-by: Yurii Shcherbak <[email protected]>
The AWS SDK-based scalers (SQS, Kinesis, DynamoDB, DynamoDB Streams, CloudWatch) never closed their underlying HTTP transport connections when Close() was called. ClearAwsConfig() only removes credential cache entries but does not shut down the HTTP client. This causes TCP connections to accumulate indefinitely, eventually exhausting file descriptors and causing the operator to lose connectivity.
Store an explicit *http.Client on each scaler struct, inject it into the AWS SDK client via options.HTTPClient, and call CloseIdleConnections() in Close(). This matches the pattern established in PR #5293 for non-AWS scalers.
Checklist
make generate-scalers-schemahas been run to update any outdated generated filesFixes #7756