fix: Prevented memory leak generated by not correctly cleaned HTTP resources#5293
Merged
Conversation
…onnections Signed-off-by: Jorge Turrado <[email protected]>
|
Thank you for your contribution! 🙏 We will review your PR as soon as possible. While you are waiting, make sure to:
Learn more about: |
Signed-off-by: Jorge Turrado Ferrero <[email protected]>
Member
Author
|
/run-e2e |
Signed-off-by: Jorge Turrado <[email protected]>
Signed-off-by: Jorge Turrado <[email protected]>
Member
Author
|
/run-e2e |
toniiiik
pushed a commit
to toniiiik/keda
that referenced
this pull request
Jan 15, 2024
…sources (kedacore#5293) Signed-off-by: Jorge Turrado <[email protected]> Signed-off-by: Jorge Turrado Ferrero <[email protected]> Signed-off-by: anton.lysina <[email protected]>
jkyros
pushed a commit
to jkyros/keda
that referenced
this pull request
Mar 27, 2024
… cleaned HTTP resources (kedacore#5293) Signed-off-by: Jorge Turrado <[email protected]> Signed-off-by: Jorge Turrado Ferrero <[email protected]>
jkyros
pushed a commit
to jkyros/keda
that referenced
this pull request
Mar 27, 2024
… cleaned HTTP resources (kedacore#5293) Signed-off-by: Jorge Turrado <[email protected]> Signed-off-by: Jorge Turrado Ferrero <[email protected]>
jkyros
pushed a commit
to jkyros/keda
that referenced
this pull request
Mar 27, 2024
… cleaned HTTP resources (kedacore#5293) Signed-off-by: Jorge Turrado <[email protected]> Signed-off-by: Jorge Turrado Ferrero <[email protected]> This wasn't a completely clean pick, I had to adjust the swift scaler client variable to be a pointer so it was nillable, but everything else was okay.
openshift-merge-bot Bot
added a commit
to openshift/kedacore-keda
that referenced
this pull request
Mar 27, 2024
OCPBUGS-30145: fix: Prevented memory leak generated by not correctly cleaned HTTP resources (kedacore#5293)
|
"scaler": "prometheusScaler", "error": "prometheus query api returned error. status: 403 response: {"message":"Credential should be scoped to a valid region. "}"} any suggestions on this error |
Member
Author
This issue was closed 4 months ago and it's totally unrelated with your topic. I'd suggest opening a new issue for your case |
5 tasks
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 16, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 18, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 21, 2026
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]>
wozniakjan
pushed a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
visualphoenix
added a commit
to visualphoenix/keda
that referenced
this pull request
May 22, 2026
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]>
rickbrouwer
added a commit
that referenced
this pull request
May 25, 2026
…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 #5293 for non-AWS scalers. Signed-off-by: Raymond Barbiero <[email protected]> Co-authored-by: Rick Brouwer <[email protected]>
shcherbak
pushed a commit
to shcherbak/keda
that referenced
this pull request
Jun 3, 2026
…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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After profiling KEDA operator looking for this memory leak, I found a weird behavior.
When I deploy the OP given SO, during the first minutes, prometheus trigger returns 404 and the memory grows, but at some point, the memory usage becomes stable and then prometheus trigger start to produce timeouts.
This impacts in 2 way, significativelly increasing the allocation of HTTP resources

And also increasing the size of the in use memory due to stored rootCAs of the clients (we are cloning the current cached certs but we aren't modifying the cloned item, so doesn't make sense, at least atm)
In order to solve these issues, this PR does:
(scaler).Close(context.Context)to close them deterministically and not delegating this action to the garbage collector. This helps to reduce the allocated resources for stablishing connectionsChecklist
Fixes #5248