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

fix: Close response to fix file descriptor leak #416

Merged
merged 1 commit into from
Jul 19, 2023

Conversation

jonathan-innis
Copy link
Member

Fixes aws/karpenter-provider-aws#4296

Description

#4296 caught an issue where Karpenter was leaking file descriptors in its webhook checks. This can be observed from the following graph that shows the Karpenter container_file_descriptors metric that tracks the number of open file descriptors on a container.

Screenshot 2023-07-19 at 10 26 58 AM

The root cause of this issue is that Golang's default HTTP client opens a connection and holds that connection open when receiving a valid response from the server, which causes a file descriptor to remain open until the connection is closed (some details described here).

This issue with not closing the response body was technically introduced in the following PR: #334 (introduced in Karpenter v0.28.0) but did not become an issue until v0.29.1 since the response returned by the server used in v0.28.0-v0.29.0 did not send a response body. Adding a response body to the response sent from the server called out to in these version also results in a file descriptor leak.

This change closes the response body and and ensures that the response body is read so that the http client can re-use the same connection from the connection pool instead of having to create another one. The file descriptor leak can seen to be resolved through the container_file_descriptors metric now:

Screenshot 2023-07-19 at 10 33 50 AM

How was this change tested?

make presubmit

  • Deployed and viewed prometheus metrics
  • Confirmation in the issue from the user who reported it

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jonathan-innis jonathan-innis requested a review from a team as a code owner July 19, 2023 17:34
@jonathan-innis jonathan-innis enabled auto-merge (squash) July 19, 2023 17:41
@coveralls
Copy link

coveralls commented Jul 19, 2023

Pull Request Test Coverage Report for Build 5602477955

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 81.29%

Totals Coverage Status
Change from base Build 5600975159: -0.1%
Covered Lines: 6904
Relevant Lines: 8493

💛 - Coveralls

pkg/operator/operator.go Outdated Show resolved Hide resolved
@jonathan-innis jonathan-innis merged commit 34e8049 into kubernetes-sigs:main Jul 19, 2023
6 checks passed
jonathan-innis added a commit to jonathan-innis/karpenter that referenced this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] v0.29.1 seems to have a file descriptor leak
4 participants