Commit d0a46c75 authored by Duggan, John's avatar Duggan, John
Browse files

Merge branch...

Merge branch '150-add-debug-statements-before-and-after-lockfile-acquisition-for-token-refresh' into 'dev'

Only hold the refresh lock for as long as is necessary and log lock attempts

Closes #150

See merge request !145
parents 43999021 b30590c8
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -9,8 +9,8 @@ variables:
  CONTAINER_GALAXY_URL: "${NDIP_DOCKER_REPOSITORY}/${CI_PROJECT_PATH}"
  CONTAINER_GALAXY_BASE_URL: "${CONTAINER_GALAXY_URL}/base"
  CONTAINER_GALAXY_COMMIT_URL: "${CONTAINER_GALAXY_URL}/commit"
  GALAXY_VERSION_PYTHON: 25.1.dev4+ornl
  GALAXY_VERSION_DOCKER: 25.1.dev4.ornl
  GALAXY_VERSION_PYTHON: 25.1.dev5+ornl
  GALAXY_VERSION_DOCKER: 25.1.dev5.ornl

# This import is for the func_rse_docker_* functions
before_script:
+20 −16
Original line number Diff line number Diff line
@@ -305,23 +305,27 @@ class AuthnzManager:
            raise exceptions.ItemAccessibilityException(msg)

    def refresh_expiring_oidc_tokens_for_provider(self, trans, auth):
        with open("/tmp/galaxy_refresh_lock", "w") as lock:
        try:
                fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
            success, message, backend = self._get_authnz_backend(auth.provider)
            if success is False:
                msg = f"An error occurred when refreshing user token on `{auth.provider}` identity provider: {message}"
                log.error(msg)
                return False
            log.debug("Attempting to acquire refresh lock")
            with open("/tmp/galaxy_refresh_lock", "w") as lock:
                fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
                log.debug("Acquired refresh lock")
                refreshed = backend.refresh(trans.sa_session, auth, 30)
            if refreshed:
                    log.debug(f"Refreshed user token via `{auth.provider}` identity provider")
                log.debug(
                    f"Refreshed user token via `{auth.provider}` identity provider"
                )
            return True
        except BlockingIOError:
            log.debug("Another process is refreshing, skipping")
            return True
        except Exception as e:
                log.exception("An error occurred when refreshing user token")
            log.exception(f"An error occurred when refreshing user token: {str(e)}")
            return False

    def refresh_expiring_oidc_tokens(self, trans, user=None):