Skip to content

Commit e3e2bee

Browse files
committed
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.
1 parent 5b605e4 commit e3e2bee

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

readthedocs/storage/azure_storage.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Django storage classes to use with Azure Blob storage service."""
55

6+
import logging
67
from azure.common import AzureMissingResourceHttpError
78
from django.conf import settings
89
from django.contrib.staticfiles.storage import ManifestFilesMixin
@@ -13,6 +14,9 @@
1314
from .mixins import OverrideHostnameMixin
1415

1516

17+
log = logging.getLogger(__name__)
18+
19+
1620
class AzureBuildMediaStorage(BuildMediaStorageMixin, OverrideHostnameMixin, AzureStorage):
1721

1822
"""An Azure Storage backend for build artifacts."""
@@ -30,6 +34,14 @@ def url(self, name, expire=None, http_method=None): # noqa
3034
"""
3135
return super().url(name, expire)
3236

37+
def exists(self, name, timeout=None):
38+
"""Override to catch timeout exception and return False."""
39+
try:
40+
return super().exists(name)
41+
except:
42+
log.exception('Timeout calling Azure .exists. name=%s', name)
43+
return False
44+
3345

3446
class AzureBuildStorage(AzureStorage):
3547

0 commit comments

Comments
 (0)