(self)
| 104 | self._refresh_lock.release() |
| 105 | |
| 106 | def _protected_refresh(self): |
| 107 | # This should only be called after acquiring the refresh lock |
| 108 | # Another thread may have already refreshed, double check refresh |
| 109 | refresh_type = self._should_refresh() |
| 110 | if not refresh_type: |
| 111 | return None |
| 112 | |
| 113 | try: |
| 114 | now = self._time_fetcher() |
| 115 | self._next_refresh = now + timedelta(seconds=self._attempt_timeout) |
| 116 | self._frozen_token = self._refresh_using() |
| 117 | except Exception: |
| 118 | logger.warning( |
| 119 | "Refreshing token failed during the %s refresh period.", |
| 120 | refresh_type, |
| 121 | exc_info=True, |
| 122 | ) |
| 123 | if refresh_type == "mandatory": |
| 124 | # This refresh was mandatory, error must be propagated back |
| 125 | raise |
| 126 | |
| 127 | if self._is_expired(): |
| 128 | # Fresh credentials should never be expired |
| 129 | raise TokenRetrievalError( |
| 130 | provider=self.method, |
| 131 | error_msg="Token has expired and refresh failed", |
| 132 | ) |
| 133 | |
| 134 | def _is_expired(self): |
| 135 | if self._frozen_token is None: |
no test coverage detected