From e3e2beeb3f2b13849020fe249cef6edf7be77e4d Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Mon, 13 Apr 2020 18:14:27 +0200 Subject: [PATCH] On Azure .exists blob timeout, log the exception and return False We have been experimenting some issues with Azure Blob storage. Our current timeout is the django-storages default (20 secs). We want to reduce it to ~2s, but without breaking the code and start returning 500. So, we log the error and return False. --- readthedocs/storage/azure_storage.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/readthedocs/storage/azure_storage.py b/readthedocs/storage/azure_storage.py index 0e66dbb0cdb..06bf457fd56 100644 --- a/readthedocs/storage/azure_storage.py +++ b/readthedocs/storage/azure_storage.py @@ -3,6 +3,7 @@ """Django storage classes to use with Azure Blob storage service.""" +import logging from azure.common import AzureMissingResourceHttpError from django.conf import settings from django.contrib.staticfiles.storage import ManifestFilesMixin @@ -13,6 +14,9 @@ from .mixins import OverrideHostnameMixin +log = logging.getLogger(__name__) + + class AzureBuildMediaStorage(BuildMediaStorageMixin, OverrideHostnameMixin, AzureStorage): """An Azure Storage backend for build artifacts.""" @@ -30,6 +34,14 @@ def url(self, name, expire=None, http_method=None): # noqa """ return super().url(name, expire) + def exists(self, name, timeout=None): + """Override to catch timeout exception and return False.""" + try: + return super().exists(name) + except: + log.exception('Timeout calling Azure .exists. name=%s', name) + return False + class AzureBuildStorage(AzureStorage):