Avoid FD spike after retrying KafkaAdminClient#32
Merged
aiven-anton merged 1 commit intomainfrom Aug 8, 2024
Merged
Conversation
aiven-anton
approved these changes
Aug 5, 2024
aiven-anton
left a comment
There was a problem hiding this comment.
LGTM 👍
Can we try and push this to kafka-python-ng? We should switch to it as upstream instead of kafka-python when we can.
kafka/admin/client.py
Outdated
Comment on lines
226
to
230
| except Exception as e: | ||
| self._metrics.close() | ||
| self._client.close() # prevent FD leak | ||
| self._closed = True | ||
| raise e |
There was a problem hiding this comment.
Suggested change
| except Exception as e: | |
| self._metrics.close() | |
| self._client.close() # prevent FD leak | |
| self._closed = True | |
| raise e | |
| except Exception: | |
| self._metrics.close() | |
| self._client.close() # prevent FD leak | |
| self._closed = True | |
| raise |
Author
There was a problem hiding this comment.
Comment addressed, thank you.
I've submitted kafka-python-ng#186 to upstream but there is a CI problem there, investigating in kafka-python-ng#187
Member
There was a problem hiding this comment.
@orange-kao Do you want to consider submitting this again, but now into original upstream who has became active again?
A caller might call kafka.KafkaAdminClient repeatedly and handle kafka.errors.NoBrokersAvailable if the broker is not available. However, each retry will cause 3 extra FD being used. Depends on how long the caller wait before retry, the FD usage can reach 300~700 before Python garbage collector collecting those FD. This commit close those FD early.
6a00955 to
dfe42d0
Compare
aiven-anton
approved these changes
Aug 8, 2024
tvainika
added a commit
that referenced
this pull request
Feb 20, 2026
This skips or reverts most of our own local patches. Socks5 support has landed upstream. Infinite loop related changes in aiven/main have been fixed one way or another as per linking to submitted issues in github. Only remaining changes are related to #32.
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.
A caller might call kafka.KafkaAdminClient repeatedly and handle kafka.errors.NoBrokersAvailable if the broker is not available.
However, each retry will cause 3 extra FD being used. Depends on how long the caller wait before retry, the FD usage can reach 300~700 before Python garbage collector collecting those FD.
This commit close those FD early.