-
Notifications
You must be signed in to change notification settings - Fork 83
SDK-199 Auth Retry policy completely bypassed #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
SDK-199 Auth Retry policy completely bypassed #987
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #987 +/- ##
==========================================
+ Coverage 69.45% 69.48% +0.03%
==========================================
Files 109 109
Lines 8944 8953 +9
==========================================
+ Hits 6212 6221 +9
Misses 2732 2732 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Ayyanchira
left a comment
There was a problem hiding this 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| if self.localStorage.email != nil || self.localStorage.userId != nil { | ||
| self.isInScheduledRefreshCallback = isScheduledRefresh | ||
| self.requestNewAuthToken(hasFailedPriorAuth: false, onSuccess: successCallback, shouldIgnoreRetryPolicy: isScheduledRefresh) | ||
| self.isInScheduledRefreshCallback = false |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaning on these tests to cover this part:
- Refresh is queued and callback fires (scheduled refresh path hits the timer closure and requests a token)
- Skip refresh when there’s no email and no userId
- Scheduled refresh respects retry limits (this is specifically exercising isInScheduledRefreshCallback + shouldPauseRetry logic invoked inside the timer closure when isScheduledRefresh == true)
- Pausing retries blocks the refresh (this hits shouldSkipTokenRefresh before scheduling the timer)
5fd4de2 to
4de526e
Compare
# Conflicts: # swift-sdk/Internal/AuthManager.swift
4de526e to
935883e
Compare
Pull Request Review CommentPlease Consider Refactoring to Option 1 from the TicketThe current fix works, but I strongly recommend simplifying to the Option 1 approach that was outlined in the ticket description. Here's why: The Core ProblemThis bug exists because The question is: should we ever allow these safety limits to be bypassed? Current Implementation: Selective BypassYour fix introduces a flag private func shouldPauseRetry(_ shouldIgnoreRetryPolicy: Bool) -> Bool {
if pauseAuthRetry {
return true
}
// Only enforces maxRetry for scheduled refreshes
if isInScheduledRefreshCallback {
return retryCount >= authRetryPolicy.maxRetry
}
// Still allows bypass in other cases
return retryCount >= authRetryPolicy.maxRetry && !shouldIgnoreRetryPolicy
}This means: Any code path that calls Option 1: Always Enforce Safety Limitsprivate func shouldPauseRetry(_ shouldIgnoreRetryPolicy: Bool) -> Bool {
if pauseAuthRetry {
return true
}
if retryCount >= authRetryPolicy.maxRetry {
return true
}
return false
}This means: No code path can bypass safety limits, ever. Period. Why This Is Better1. Prevents ALL infinite loops, not just scheduled refresh loops If tomorrow someone adds code that calls 2. No state management complexity Your approach requires:
Option 1 requires: none of that. 3. Thread-safe by default Flag management patterns can be racy if methods get called from multiple threads. Option 1 has no such risk. 4. Matches the stated intent The ticket says: "pauseAuthRetry and maxRetry are safety controls that should ALWAYS be respected." Your implementation respects them sometimes. Option 1 respects them always. 5. Fewer lines of code Current: 12 lines in Simple code is maintainable code. What About
|
sumeruchat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with Claude that we should take the simpler approach @joaodordio
@sumeruchat We need to have a bigger discussion about this. The solution you are recommending based on Claude, removes the We need to further discuss offline why we need that flag and what the purpose of it is. |
🔹 Jira Ticket(s)
✏️ Description
Fixes auth retry for expired JWT refresh: scheduled token refresh no longer bypasses
pauseAuthRetriesorauthRetryPolicy.maxRetry, preventing runaway/infiniteonAuthTokenRequestedloops.Added unit tests to lock pause + maxRetry behavior on scheduled refresh, and reset retry count after a successful refresh is queued.