summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Schultz <aschultz@redhat.com>2019-08-01 14:39:46 -0600
committerBrian Rosmaita <rosmaita.fossdev@gmail.com>2020-03-17 21:49:47 +0000
commit1aba8f2d248040364e690dd8dc7f3a508baed631 (patch)
treea633f2dd7f798173758865c8208702f63995a29b
parentfd83a8eee7d672076413369497a6602025166c4d (diff)
downloadpython-glanceclient-stable/train.tar.gz
Cleanup session objecttrain-em2.17.1stable/train
If a session object is not provided to the get_http_client function (as is done via osc), the glance client uses it's own HTTPClient class. This class creates a session but does not properly close it when it is done. This can lead to resource warnings about unclosed sockets. This change adds a __del__() to the HTTPClient class to close out the session correctly. Change-Id: Idccff338fa84c46ca0e429bb533a2a5217205eef Closes-Bug: #1838694 (cherry picked from commit 436f797e8db2fc11b7dace7cb7020e4d44a3d2d7)
-rw-r--r--glanceclient/common/http.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py
index 17d7cc7..78c4bc5 100644
--- a/glanceclient/common/http.py
+++ b/glanceclient/common/http.py
@@ -183,6 +183,15 @@ class HTTPClient(_BaseHTTPClient):
self.session.cert = (kwargs.get('cert_file'),
kwargs.get('key_file'))
+ def __del__(self):
+ if self.session:
+ try:
+ self.session.close()
+ except Exception as e:
+ LOG.exception(e)
+ finally:
+ self.session = None
+
@staticmethod
def parse_endpoint(endpoint):
return netutils.urlsplit(endpoint)