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)