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

Close google/azure/s3 client when closing GoogleTransfer object [DDB-1160] #187

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

kmichel-aiven
Copy link
Collaborator

@kmichel-aiven kmichel-aiven commented Jul 18, 2024

About this change - What it does

GoogleTransfer objects create clients and never close the client, if we create many clients, we leak sockets.

Add a API to close a Transfer object and implement it in the GoogleTransfer subclass to close the google client.

Also implement it in Azure/S3 transfer objects for consistency (and hopefully one day we'll stop creating buckets during __init__, which will make the objects creation cheaper and free of side-effects.)

Why this way

Because if we leak socket, then we eventually crash.

@kmichel-aiven kmichel-aiven changed the title Close google client when closing GoogleTransfer object [DDB-1148] Close google client when closing GoogleTransfer object [DDB-1160] Jul 18, 2024
@kmichel-aiven kmichel-aiven marked this pull request as ready for review July 19, 2024 12:18
@kmichel-aiven kmichel-aiven requested a review from a team July 19, 2024 12:18
@@ -82,6 +82,9 @@ def __init__(
self.notifier = notifier or NullNotifier()
self.stats = StatsClient(statsd_info)

def close(self) -> None:
Copy link
Contributor

@Khatskevich Khatskevich Jul 19, 2024

Choose a reason for hiding this comment

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

I do not understand who is calling this close call?
I could not find api in this repo which will enforce the close call.
Should the Transfer object "user" remember to close the object after every usage?

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise a client pool may be used. Or any other simple way which makes it easy to use and reliable

Copy link
Contributor

@joelynch joelynch Jul 19, 2024

Choose a reason for hiding this comment

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

Close is part of the API for this class. A docstring might help here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Files, sockets, etc... need to be closed to reliably not have leaks, the same is true for APIs that use them.

I'll add a docstring to make it clear that this is part of the API.

Copy link
Contributor

@joelynch joelynch left a comment

Choose a reason for hiding this comment

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

Seems good to me.

@@ -188,10 +188,18 @@ def __init__(
self.proxy_info = proxy_info
self.google_creds = get_credentials(credential_file=credential_file, credentials=credentials)
self.gs: Optional[Resource] = self._init_google_client()
self.gs_object_client = None
self.gs_object_client: Optional[Any] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
self.gs_object_client: Optional[Any] = None
self.gs_object_client: Any = None

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@kmichel-aiven kmichel-aiven marked this pull request as draft July 22, 2024 06:20
@kmichel-aiven kmichel-aiven changed the title Close google client when closing GoogleTransfer object [DDB-1160] Close google/azure/s3 client when closing GoogleTransfer object [DDB-1160] Jul 22, 2024
@kmichel-aiven kmichel-aiven marked this pull request as ready for review July 23, 2024 06:04
@kmichel-aiven kmichel-aiven requested a review from joelynch July 23, 2024 08:07
Copy link
Contributor

@joelynch joelynch left a comment

Choose a reason for hiding this comment

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

LGTM

@joelynch joelynch merged commit 74e5fe5 into main Jul 23, 2024
9 checks passed
@joelynch joelynch deleted the kmichel-close branch July 23, 2024 12:19
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.

3 participants