From 7751fede5a4733130e210b62ab1f99ab9763c9c7 Mon Sep 17 00:00:00 2001 From: Nick Lang Date: Fri, 18 May 2018 14:30:31 -0600 Subject: [PATCH] add wait on delay (#794) --- elasticsearch/transport.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/elasticsearch/transport.py b/elasticsearch/transport.py index 0326aaa4..b7801bc5 100644 --- a/elasticsearch/transport.py +++ b/elasticsearch/transport.py @@ -294,7 +294,7 @@ class Transport(object): if body is not None: try: - body = body.encode('utf-8', 'surrogatepass') + body = body.encode('utf-8', 'surrogatepass') except (UnicodeDecodeError, AttributeError): # bytes/str - no need to re-encode pass @@ -311,6 +311,10 @@ class Transport(object): connection = self.get_connection() try: + # add a delay before attempting the next retry + # 0, 1, 3, 7, etc... + delay = 2**attempt - 1 + time.sleep(delay) status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout) except TransportError as e: