From c2b8ef579ae9bcdfaa28c0408d17227e3956f836 Mon Sep 17 00:00:00 2001 From: Albert Wang Date: Fri, 8 Nov 2024 22:57:35 -0800 Subject: [PATCH] Rewrite process_response retries (#753) --- silk/middleware.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/silk/middleware.py b/silk/middleware.py index 5b4a8cd5..f1843777 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 = 2 + 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