Move fake session to HTTPClient

The fake session object is to prevent a cyclical dependency between
HTTPClient and the session from leaving hanging session objects around.

This is still necessary if you construct a client the old way however if
you are using the session properly then there is no cyclical dependency
and so we shouldn't prevent people using the connection pooling
advantages of the session.

Related-Bug: #1282089
Change-Id: Ifca2c7ddd95a81af01ee43246ecc8e74abf95602
This commit is contained in:
Jamie Lennox 2014-07-23 09:14:56 +10:00
parent c9ae9d1fa2
commit 8fcacdc7c7
2 changed files with 19 additions and 17 deletions

View File

@ -22,6 +22,7 @@ OpenStack Client interface. Handles the REST calls and responses.
import logging
import pkg_resources
import requests
from six.moves.urllib import parse as urlparse
try:
@ -66,6 +67,22 @@ USER_AGENT = client_session.USER_AGENT
request = client_session.request
class _FakeRequestSession(object):
"""This object is a temporary hack that should be removed later.
Keystoneclient has a cyclical dependency with its managers which is
preventing it from being cleaned up correctly. This is always bad but when
we switched to doing connection pooling this object wasn't getting cleaned
either and so we had left over TCP connections hanging around.
Until we can fix the client cleanup we rollback the use of a requests
session and do individual connections like we used to.
"""
def request(self, *args, **kwargs):
return requests.request(*args, **kwargs)
class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
version = None
@ -238,6 +255,7 @@ class HTTPClient(baseclient.Client, base.BaseAuthPlugin):
self._auth_token = None
if not session:
kwargs['session'] = _FakeRequestSession()
session = client_session.Session.construct(kwargs)
session.auth = self

View File

@ -49,22 +49,6 @@ def request(url, method='GET', **kwargs):
return Session().request(url, method=method, **kwargs)
class _FakeRequestSession(object):
"""This object is a temporary hack that should be removed later.
Keystoneclient has a cyclical dependency with its managers which is
preventing it from being cleaned up correctly. This is always bad but when
we switched to doing connection pooling this object wasn't getting cleaned
either and so we had left over TCP connections hanging around.
Until we can fix the client cleanup we rollback the use of a requests
session and do individual connections like we used to.
"""
def request(self, *args, **kwargs):
return requests.request(*args, **kwargs)
class Session(object):
user_agent = None
@ -113,7 +97,7 @@ class Session(object):
for forever/never. (optional, default to 30)
"""
if not session:
session = _FakeRequestSession()
session = requests.Session()
self.auth = auth
self.session = session