Skip to content

Commit 7751fed

Browse files
authored
add wait on delay (elastic#794)
1 parent 206e0d6 commit 7751fed

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

elasticsearch/transport.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def perform_request(self, method, url, headers=None, params=None, body=None):
294294

295295
if body is not None:
296296
try:
297-
body = body.encode('utf-8', 'surrogatepass')
297+
body = body.encode('utf-8', 'surrogatepass')
298298
except (UnicodeDecodeError, AttributeError):
299299
# bytes/str - no need to re-encode
300300
pass
@@ -311,6 +311,10 @@ def perform_request(self, method, url, headers=None, params=None, body=None):
311311
connection = self.get_connection()
312312

313313
try:
314+
# add a delay before attempting the next retry
315+
# 0, 1, 3, 7, etc...
316+
delay = 2**attempt - 1
317+
time.sleep(delay)
314318
status, headers_response, data = connection.perform_request(method, url, params, body, headers=headers, ignore=ignore, timeout=timeout)
315319

316320
except TransportError as e:

0 commit comments

Comments
 (0)