Browse Source

Cleanup session object

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 436f797e8d)
tags/2.17.1^0
Alex Schultz 11 months ago
committed by Brian Rosmaita
parent
commit
1aba8f2d24
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      glanceclient/common/http.py

+ 9
- 0
glanceclient/common/http.py View File

@@ -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)


Loading…
Cancel
Save