Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions simplipy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
def get_expiration_datetime(expires_in_seconds: int) -> datetime:
"""Get a token expiration datetime as an offset of UTC now + a number of seconds.

Note that we pad the value to ensure the token doesn't expire without us knowing.
Note that we add some padding to the datetime. This ensures that multiple tasks
attempting to refresh within microseconds of one another are turned away.
"""
return datetime.utcnow() + (
timedelta(seconds=expires_in_seconds - DEFAULT_EXPIRATION_PADDING)
timedelta(seconds=expires_in_seconds + DEFAULT_EXPIRATION_PADDING)
)


Expand Down Expand Up @@ -175,7 +176,7 @@ async def _async_handle_on_backoff(self, _: dict[str, Any]) -> None:
# been refreshed within the expiration window (and we lock the attempt so
# other requests can't try it at the same time):
async with self._backoff_refresh_lock:
if datetime.utcnow() < self._access_token_expire_dt:
if datetime.utcnow() <= self._access_token_expire_dt:
return

LOGGER.info("401 detected; attempting refresh token")
Expand Down