summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Cordasco <ian.cordasco@rackspace.com>2015-01-21 14:38:02 -0600
committerChristian Schwede <christian.schwede@enovance.com>2015-02-25 11:00:56 +0000
commit8756591b0ad24320a0b6fa3b2f7513e17ec46b6c (patch)
tree59bc445535ccfcbfbf657c19523fe9e272e6cd54
parent731707f06da899fa8fb2d521e35f850a2e1652ab (diff)
downloadpython-swiftclient-8756591b0ad24320a0b6fa3b2f7513e17ec46b6c.tar.gz
Release connection after consuming the content
When using stream=True, we need to make sure we release a connection back to the connection pool to avoid warnings clogging up the logs. We can do this by releasing the connection once we've read all the content from the response. In situations where stream=False, requests already does this for us. Related-bug: 1424732 Closes-bug: 1341777 Change-Id: Id1c72ad86135a49d4b985992d788736b65f7dbda
-rw-r--r--swiftclient/client.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index 985cad8..0c6d8d3 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -21,7 +21,6 @@ import socket
import requests
import logging
import warnings
-import functools
try:
from simplejson import loads as json_loads
except ImportError:
@@ -233,10 +232,22 @@ class HTTPConnection(object):
def getheader(k, v=None):
return old_getheader(k.lower(), v)
+ def releasing_read(*args, **kwargs):
+ kwargs['decode_content'] = True
+ chunk = self.resp.raw.read(*args, **kwargs)
+ if not chunk:
+ # NOTE(sigmavirus24): Release the connection back to the
+ # urllib3's connection pool. This will reduce the number of
+ # log messages seen in bug #1341777. This does not actually
+ # close a socket. It will also prevent people from being
+ # mislead as to the cause of a bug as in bug #1424732.
+ self.resp.close()
+ return chunk
+
self.resp.getheaders = getheaders
self.resp.getheader = getheader
- self.resp.read = functools.partial(self.resp.raw.read,
- decode_content=True)
+ self.resp.read = releasing_read
+
return self.resp