From c82219ea0a651b01d7b9dd91286450e8ecab8fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Sat, 18 Jan 2014 21:33:04 +0100 Subject: [PATCH] Make sure we clean up correctly after failed thrift connection --- elasticsearch/connection/thrift.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elasticsearch/connection/thrift.py b/elasticsearch/connection/thrift.py index 7f97199d..10c616e4 100644 --- a/elasticsearch/connection/thrift.py +++ b/elasticsearch/connection/thrift.py @@ -56,6 +56,7 @@ class ThriftConnection(PoolingConnection): parameters=params, body=body) start = time.time() + tclient = None try: tclient = self._get_connection() response = tclient.execute(request) @@ -64,7 +65,8 @@ class ThriftConnection(PoolingConnection): self.log_request_fail(method, url, body, time.time() - start, exception=e) raise ConnectionError('N/A', str(e), e) finally: - self._release_connection(tclient) + if tclient: + self._release_connection(tclient) if not (200 <= response.status < 300) and response.status not in ignore: self.log_request_fail(method, url, body, duration, response.status)