If a session object is not provided to the glance client, the HTTPClient defined in glanceclient.common.http will create a session object. This session object leaks open connections because it is not properly closed when the object is no longer needed. This leads to a ResourceWarning about an unclosed socket:
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.24.2', 55912), raddr=('192.168.24.2', 13292)>
Example code:
$ cat g.py
#!/usr/bin/python3 -Wd
import glanceclient.common.http as h
client = h.get_http_client(endpoint='https://192.168.24.2:13292',
token='<my magical token>',
cacert='/etc/pki/ca-trust/source/anchors/cm-local-ca.pem',
insecure=False)
print(client.get('/v2/images'))
Results in:
$ ./g.py
/usr/lib64/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /usr/lib/python3.6/site-packages/repoze: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
/usr/lib64/python3.6/importlib/_bootstrap_external.py:426: ImportWarning: Not importing directory /usr/lib/python3.6/site-packages/paste: missing __init__
_warnings.warn(msg.format(portions[0]), ImportWarning)
/usr/lib/python3.6/site-packages/pytz/__init__.py:499: ResourceWarning: unclosed file <_io.TextIOWrapper name='/usr/share/zoneinfo/zone.tab' mode='r' encoding='UTF-8'>
for l in open(os.path.join(_tzinfo_dir, 'zone.tab'))
/usr/lib/python3.6/site-packages/eventlet/patcher.py:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
(<Response [200]>, {'images': [{<image data>}], 'first': '/v2/images', 'schema': '/v2/schemas/images'})
sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('192.168.24.2', 55912), raddr=('192.168.24.2', 13292)>
This can be mitigated by adding a __del__ function to glanceclient.common.http.HTTPClient that closes the session.
https:/ /review. opendev. org/#/c/ 674133/