Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Elasticsearch client is closed after each reconciliation #8175

Merged
merged 3 commits into from
Nov 4, 2024

Conversation

naemono
Copy link
Contributor

@naemono naemono commented Nov 1, 2024

Resolves #8174

While investigating #8174 a couple pprof heap dumps were taken over the course of a couple of days, and compared using the diff capabilities of pprof:

go tool pprof -http=:8082 -no_browser -diff_base dump-1.out.gz dump-2.out.gz dump-3.out.gz

This brought to light the following function in the autoscaling controller (attemptOnlineReconciliation), which seems to have had it's heap allocations grow by about %2000 since the first dump:
image

Upon further investigation, we don't appear to be closing idle connections in the underlying http client, which could be leaking goroutines, and therefore leading to this memory increase.

Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
@naemono naemono added the >bug Something isn't working label Nov 1, 2024
Copy link
Collaborator

@pebrc pebrc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great finding. I am still a bit confused how this slipped through. I think you have to adjust the fake client too to not panic when close is called

github.com/elastic/cloud-on-k8s/v2/pkg/controller/autoscaling/elasticsearch.(*fakeEsClient).Close(0xc00095c700?)

Add close func to fake esclient struct.

Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
@naemono
Copy link
Contributor Author

naemono commented Nov 4, 2024

Signs from initial testing of the latest build show good signs, as the memory seems stable. I'm going to let it run the rest of the day to ensure before merging.

@pebrc pebrc added the v2.15.0 label Nov 4, 2024
Copy link
Contributor

@kvalliyurnatt kvalliyurnatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Find!

@naemono
Copy link
Contributor Author

naemono commented Nov 4, 2024

image

Ok, you can see where I configured with the new version, and it's been a straight line of heap consumption at this point. I'm going to go ahead and merge this, and create a backport.

@naemono naemono merged commit 602866e into elastic:main Nov 4, 2024
5 checks passed
@naemono naemono deleted the autoscaler-always-close-es-client branch November 4, 2024 19:54
@naemono
Copy link
Contributor Author

naemono commented Nov 4, 2024

💚 All backports created successfully

Status Branch Result
2.15

Questions ?

Please refer to the Backport tool documentation

naemono added a commit to naemono/cloud-on-k8s that referenced this pull request Nov 4, 2024
* Ensure esclient is closed after each reconcile.
* Also call close in stackconfigpolicy.
* Add close func to fake esclient struct.
* Also add close to fakeseClient in stackconfigpolicy

---------

Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
(cherry picked from commit 602866e)
naemono added a commit that referenced this pull request Nov 4, 2024
* Ensure esclient is closed after each reconcile.
* Also call close in stackconfigpolicy.
* Add close func to fake esclient struct.
* Also add close to fakeseClient in stackconfigpolicy

---------

Signed-off-by: Michael Montgomery <mmontg1@gmail.com>
(cherry picked from commit 602866e)
@rhr323 rhr323 changed the title Ensure esclient is closed after each reconcile. Ensure Elasticsearch client is closed after each reconciliation Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Something isn't working v2.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential memory leak in the ECK Autoscaler.
3 participants