diff options
author | Sybren A. Stüvel <sybren@stuvel.eu> | 2019-07-18 15:54:09 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2019-07-18 15:55:00 +0300 |
commit | 2b62b3d6f8e03af5eb931534bbbd02d63acee351 (patch) | |
tree | d4e0032e91fc017a33b75fb5978f5714af6cd143 | |
parent | 184f7341bd171d411a326de6b4804b61c9903ad2 (diff) |
Updated Blender ID add-on from upstream (2.0 to 2.1)
This should fix T66881.
Includes:
96f5449 (2019-07-18) Bumped version to 2.1.0
3931e8f (2019-07-18) Add a timeout to communication with Blender ID
-rw-r--r-- | blender_id/CHANGELOG.md | 7 | ||||
-rw-r--r-- | blender_id/__init__.py | 2 | ||||
-rw-r--r-- | blender_id/communication.py | 19 |
3 files changed, 20 insertions, 8 deletions
diff --git a/blender_id/CHANGELOG.md b/blender_id/CHANGELOG.md index 24fd4527..62f743a7 100644 --- a/blender_id/CHANGELOG.md +++ b/blender_id/CHANGELOG.md @@ -1,5 +1,12 @@ # Blender ID Add-on Changelog +# Version 2.1 (released 2019-08-18) + +- Add a timeout to communication with Blender ID. Any attempt at communication will now time out + after 5 seconds, and be re-tried 5 times. Combined a request can "hang" for a minute, but not + longer than that. + + # Version 2.0 (released 2019-07-09) - Require Blender 2.80+. diff --git a/blender_id/__init__.py b/blender_id/__init__.py index c39e03fe..4790b86f 100644 --- a/blender_id/__init__.py +++ b/blender_id/__init__.py @@ -23,7 +23,7 @@ bl_info = { 'name': 'Blender ID authentication', 'author': 'Sybren A. Stüvel, Francesco Siddi, and Inês Almeida', - 'version': (2, 0, 0), + 'version': (2, 1, 0), 'blender': (2, 80, 0), 'location': 'Add-on preferences', 'description': diff --git a/blender_id/communication.py b/blender_id/communication.py index 0cef6faa..6ebb3ea3 100644 --- a/blender_id/communication.py +++ b/blender_id/communication.py @@ -30,6 +30,9 @@ BLENDER_ID_ENDPOINT = 'https://id.blender.org/' # Will become a requests.Session at the first request to Blender ID. requests_session = None +# Request timeout, in seconds. +REQUESTS_TIMEOUT = 5.0 + class BlenderIdCommError(RuntimeError): """Raised when there was an error communicating with Blender ID""" @@ -56,7 +59,7 @@ def host_label(): def blender_id_session(): """Returns the Requests session, creating it if necessary.""" global requests_session - import requests + import requests.adapters if requests_session is not None: return requests_session @@ -66,7 +69,7 @@ def blender_id_session(): # Retry with backoff factor, so that a restart of Blender ID or hickup # in the connection doesn't immediately fail the request. retries = requests.packages.urllib3.util.retry.Retry( - total=10, + total=5, backoff_factor=0.05, ) http_adapter = requests.adapters.HTTPAdapter(max_retries=retries) @@ -129,7 +132,7 @@ def blender_id_server_authenticate(username, password) -> AuthResult: url = blender_id_endpoint('u/identify') session = blender_id_session() try: - r = session.post(url, data=payload, verify=True) + r = session.post(url, data=payload, verify=True, timeout=REQUESTS_TIMEOUT) except (requests.exceptions.SSLError, requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e: @@ -169,7 +172,7 @@ def blender_id_server_validate(token) -> typing.Tuple[typing.Optional[str], typi url = blender_id_endpoint('u/validate_token') session = blender_id_session() try: - r = session.post(url, data={'token': token}, verify=True) + r = session.post(url, data={'token': token}, verify=True, timeout=REQUESTS_TIMEOUT) except requests.exceptions.ConnectionError: log.exception('error connecting to Blender ID at %s', url) return None, 'Unable to connect to Blender ID' @@ -204,7 +207,7 @@ def blender_id_server_logout(user_id, token): session = blender_id_session() try: r = session.post(blender_id_endpoint('u/delete_token'), - data=payload, verify=True) + data=payload, verify=True, timeout=REQUESTS_TIMEOUT) except (requests.exceptions.SSLError, requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e: @@ -263,7 +266,8 @@ def make_authenticated_call(method, url, auth_token, data): blender_id_endpoint(url), data=data, headers={'Authorization': 'Bearer %s' % auth_token}, - verify=True) + verify=True, + timeout=REQUESTS_TIMEOUT) except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e: raise BlenderIdCommError(str(e)) @@ -292,7 +296,8 @@ def send_token_to_subclient(webservice_endpoint: str, user_id: str, data={'user_id': user_id, 'subclient_id': subclient_id, 'token': subclient_token}, - verify=True) + verify=True, + timeout=REQUESTS_TIMEOUT) r.raise_for_status() except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError) as e: |