-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
@@ -82,6 +82,9 @@ def __init__( | |||
self.notifier = notifier or NullNotifier() | |||
self.stats = StatsClient(statsd_info) | |||
|
|||
def close(self) -> None: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
rohmu/object_storage/google.py
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
self.gs_object_client: Optional[Any] = None | |
self.gs_object_client: Any = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
[DDB-1160]
5c64b5b
to
7ef096d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.