Page MenuHome

Blenderkit rerequests are killing blender (2.9.3. LTS)
Closed, DuplicatePublic


System Information
Operating system: MacOS Big Sur
Graphics card: -

Blender Version
Broken: 2.9.3
Worked: 2.8.*

Short description of error

When an HTTP request fails repeatedly in the try/catch on line 36 of blenderkit/, it recurses infinitely, causing a crash of Blender.

The change responsible is (I believe) this patch:

28 def rerequest(method, url, **kwargs):
29     # first get any additional args from kwargs
30     immediate = False
31     if kwargs.get('immediate'):
32         immediate = kwargs['immediate']
33         kwargs.pop('immediate')
34     # first normal attempt
35     try:
36         response = requests.request(method, url, **kwargs)
37     except:
38         return rerequest(method, url, **kwargs)

Exact steps for others to reproduce the error

  1. Enable Blenderkit
  2. Go to your favorite coffeeshop and connect to their janky wifi, but don't log in
  3. Encounter HTTPS request failures (i.e. not a complete 401 HTTP response, but an actual failure)
  4. Let Blenderkit recurse itself to death

Recommended fix

Increment a counter and only recurse N times before failing. Ideally, we should also wait a few sec before retrying each time, since this causes immediate, extremely-deep recursion as-is.

Event Timeline

I think a patch looks something like this:

---	2021-06-09 10:55:53.000000000 -0400
+++	2021-06-09 10:58:54.000000000 -0400
@@ -24,6 +24,7 @@
 import logging
 bk_logger = logging.getLogger('rerequests')


 def rerequest(method, url, **kwargs):
     # first get any additional args from kwargs
@@ -31,11 +32,14 @@
     if kwargs.get('immediate'):
         immediate = kwargs['immediate']
+    retries_remaining = kwargs.get("retries", DEFAULT_MAX_RETRIES)
     # first normal attempt
         response = requests.request(method, url, **kwargs)
-    except:
-        return rerequest(method, url, **kwargs)
+    except Exception as e:
+        if retries_remaining <= 0:
+            raise e
+        return rerequest(method, url, retries=retries_remaining - 1, **kwargs)

     bk_logger.debug(url+ str( kwargs))

i don't have Blender cloned at the moment but I'm happy to make the change later to claim my Internet Points if no one beats me to it.

Oh shoot @Robert Guetzkow (rjg) I'm sorry, I was sure I had checked for dups...