diff --git a/server/portal/apps/auth/models.py b/server/portal/apps/auth/models.py index a49e85b29..96bcb2e6a 100644 --- a/server/portal/apps/auth/models.py +++ b/server/portal/apps/auth/models.py @@ -6,6 +6,7 @@ from django.conf import settings from tapipy.tapis import Tapis from django.db import transaction +from threading import Lock logger = logging.getLogger(__name__) @@ -81,7 +82,11 @@ def client(self): with transaction.atomic(): if self.expired: try: - client.refresh_tokens() + lock = Lock() + logger.debug("getting lock") + with lock: + logger.debug("refreshing token with lock") + client.refresh_tokens() except Exception: logger.exception('Tapis Token refresh failed') raise