Blenderkit rerequests are killing blender (2.9.3. LTS) #89003

Closed
opened 2021-06-09 16:54:15 +02:00 by Jordan Matelsky · 5 comments

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/rerequests.py, it recurses infinitely, causing a crash of Blender.
(/Applications/Blender.app/Contents/Resources/2.93/scripts/addons/blenderkit/rerequests.py)

The change responsible is (I believe) this patch:
https://developer.blender.org/rBAdb4f7e2dc66d437b205f8097c2bdf9097b5c8834

 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.

**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/rerequests.py`, it recurses infinitely, causing a crash of Blender. (`/Applications/Blender.app/Contents/Resources/2.93/scripts/addons/blenderkit/rerequests.py`) The change responsible is (I believe) this patch: https://developer.blender.org/rBAdb4f7e2dc66d437b205f8097c2bdf9097b5c8834 ``` 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.

Added subscriber: @j6m8

Added subscriber: @j6m8

Closed as duplicate of blender/blender-addons#88901

Closed as duplicate of blender/blender-addons#88901

I think a patch looks something like this:

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

+DEFAULT_MAX_RETRIES = 10

 def rerequest(method, url, **kwargs):
     # first get any additional args from kwargs
@@ -31,11 +32,14 @@
     if kwargs.get('immediate'):
         immediate = kwargs['immediate']
         kwargs.pop('immediate')
+    retries_remaining = kwargs.get("retries", DEFAULT_MAX_RETRIES)
     # first normal attempt
     try:
         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))
     bk_logger.debug(response.status_code)

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.

I think a patch looks something like this: ``` --- rerequests.py 2021-06-09 10:55:53.000000000 -0400 +++ rerequests.patch.py 2021-06-09 10:58:54.000000000 -0400 @@ -24,6 +24,7 @@ import logging bk_logger = logging.getLogger('rerequests') +DEFAULT_MAX_RETRIES = 10 def rerequest(method, url, **kwargs): # first get any additional args from kwargs @@ -31,11 +32,14 @@ if kwargs.get('immediate'): immediate = kwargs['immediate'] kwargs.pop('immediate') + retries_remaining = kwargs.get("retries", DEFAULT_MAX_RETRIES) # first normal attempt try: 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)) bk_logger.debug(response.status_code) ``` 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.

Added subscriber: @rjg

Added subscriber: @rjg

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

Oh shoot @rjg I'm sorry, I was sure I had checked for dups...
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#89003
No description provided.