Skip to content

Commit c2b8ef5

Browse files
authored
Rewrite process_response retries (jazzband#753)
1 parent a180d4c commit c2b8ef5

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

silk/middleware.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,18 @@ def _process_response(self, request, response):
167167
Logger.debug('Process response done.')
168168

169169
def process_response(self, request, response):
170+
max_attempts = 2
171+
attempts = 1
170172
if getattr(request, 'silk_is_intercepted', False):
171-
while True:
173+
while attempts <= max_attempts:
174+
if attempts > 1:
175+
Logger.debug('Retrying _process_response; attempt %s' % attempts)
172176
try:
173177
self._process_response(request, response)
174-
except (AttributeError, DatabaseError):
175-
Logger.debug('Retrying _process_response')
176-
self._process_response(request, response)
177-
finally:
178178
break
179+
except (AttributeError, DatabaseError):
180+
if attempts >= max_attempts:
181+
Logger.warn('Exhausted _process_response attempts; not processing request')
182+
break
183+
attempts += 1
179184
return response

0 commit comments

Comments
 (0)