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

Avoid FD spike after retrying KafkaAdminClient #32

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

orange-kao
Copy link

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.

Copy link

@aiven-anton aiven-anton left a comment

Choose a reason for hiding this comment

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

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.

Comment on lines 226 to 230
except Exception as e:
self._metrics.close()
self._client.close() # prevent FD leak
self._closed = True
raise e

Choose a reason for hiding this comment

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

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

Copy link
Author

Choose a reason for hiding this comment

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

Comment addressed, thank you.
I've submitted wbarnha#186 to upstream but there is a CI problem there, investigating in wbarnha#187

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.
@aiven-anton aiven-anton merged commit e0ab864 into main Aug 8, 2024
@aiven-anton aiven-anton deleted the orange-avoid-fd-spike branch August 8, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants