Skip to content

Conversation

@joaodordio
Copy link
Member

@joaodordio joaodordio commented Dec 15, 2025

🔹 Jira Ticket(s)

✏️ Description

Fixes auth retry for expired JWT refresh: scheduled token refresh no longer bypasses pauseAuthRetries or authRetryPolicy.maxRetry, preventing runaway/infinite onAuthTokenRequested loops.

Added unit tests to lock pause + maxRetry behavior on scheduled refresh, and reset retry count after a successful refresh is queued.

@joaodordio joaodordio self-assigned this Dec 15, 2025
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.41%. Comparing base (abbab6a) to head (5fd4de2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #987      +/-   ##
==========================================
+ Coverage   69.26%   69.41%   +0.15%     
==========================================
  Files         109      109              
  Lines        8917     8926       +9     
==========================================
+ Hits         6176     6196      +20     
+ Misses       2741     2730      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joaodordio joaodordio marked this pull request as ready for review December 15, 2025 23:37
Copy link
Member

@Ayyanchira Ayyanchira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made some comments

let timeIntervalToRefresh = TimeInterval(expirationDate) - dateProvider.currentDate.timeIntervalSince1970 - expirationRefreshPeriod
if timeIntervalToRefresh > 0 {
scheduleAuthTokenRefreshTimer(interval: timeIntervalToRefresh, isScheduledRefresh: true, successCallback: onSuccess)
resetRetryCount()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schedule wont necessarily guarantees successful retrieval of token. Should we reset the count here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that since the schedule is fired, we can reset the retries. regardless of its success.

Comment on lines +70 to +79
if pauseAuthRetry {
return true
}

// Scheduled refresh should never bypass retry safety limits.
if isInScheduledRefreshCallback {
return retryCount >= authRetryPolicy.maxRetry
}

return retryCount >= authRetryPolicy.maxRetry && !shouldIgnoreRetryPolicy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks simplified and better.

Comment on lines +229 to +232
if self.localStorage.email != nil || self.localStorage.userId != nil {
self.isInScheduledRefreshCallback = isScheduledRefresh
self.requestNewAuthToken(hasFailedPriorAuth: false, onSuccess: successCallback, shouldIgnoreRetryPolicy: isScheduledRefresh)
self.isInScheduledRefreshCallback = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be well tested manually as well

Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants