From b1115c1ef959e7517b043e0b9ecc930bc0ffce23 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Sun, 3 Nov 2024 12:09:44 -0800 Subject: [PATCH] Rewrite process_response retries --- silk/middleware.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/silk/middleware.py b/silk/middleware.py index 5b4a8cd5..3ad2e5b1 100644 --- a/silk/middleware.py +++ b/silk/middleware.py @@ -167,13 +167,18 @@ def _process_response(self, request, response): Logger.debug('Process response done.') def process_response(self, request, response): + max_attempts = 3 + attempts = 1 if getattr(request, 'silk_is_intercepted', False): - while True: + while attempts <= max_attempts: + if attempts > 1: + Logger.debug('Retrying _process_response; attempt %s' % attempts) try: self._process_response(request, response) - except (AttributeError, DatabaseError): - Logger.debug('Retrying _process_response') - self._process_response(request, response) - finally: break + except (AttributeError, DatabaseError): + if attempts >= max_attempts: + Logger.warn('Exhausted _process_response attempts; not processing request') + break + attempts += 1 return response