CheckAuthorizationStatus can lead to infinite loops
Categories
(Application Services :: Fxa Client, defect)
Tracking
(Not tracked)
People
(Reporter: bdk, Unassigned)
References
(Depends on 1 open bug, Blocks 1 open bug)
Details
(Whiteboard: [fxsync-])
Applications send the CheckAuthorizationStatus event after a 401 error. If that event succeeds the applications will typically attempt to retry the operation that generated a 401 error. This can lead to an infinite loop:
- Operation fails with a 401
CheckAuthorizationStatussucceeds, but doesn't resolve the underlying problem. Note that https://bugzilla.mozilla.org/show_bug.cgi?id=2060539 makes this more likely, since if you're in theConnectedstate then we'll "succeed" unless the fxa server actively tells us that the refresh token is bad.- GOTO 1
We should figure out a way to avoid this.
Fixing the other children of https://bugzilla.mozilla.org/show_bug.cgi?id=2084259 will make this less likely, but it seems like there's always going to be the chance of a bug in our code or the fxa server code that causes this.
Updated•1 month ago
|
| Reporter | ||
Comment 1•1 month ago
|
||
I can think of two ways to fix this:
Least intrusive: Add a circuit breaker. If we get N 401 errors in a row, then we unconditionally transition to AuthIssues.
More intrusive, but maybe better in the long-run: Rework the clients to use process_event for these operations. process_event has it's own auth recovery check, but only ever calls check_authorization_status once.
For example, we could add a profile: Option<Profile> field to the FxaState::Connected variant and FxaEvent::GetProfile which attempts to fill that out. On the application side, instead of calling get_profile, they would send FxaEvent::GetProfile which would transition them to either FxaState::AuthIssues or FxaStateConnected { profile: Some(...) }
| Reporter | ||
Comment 2•20 days ago
|
||
After thinking through this a bit more, one issue seems to be the way that we handle auth recovery. When we detect that we've recovered from auth issues, we do the following:
- Fetching the profile
- Refresh the device constellation state
- Updates the account state based on the profile/device constellation. This fires off some more events for downstream components. Side note: this seems potentially buggy, how do we know that this runs after the previous two? I'll leave that for a separate issue though.
This issue happens because 1 and 2 can fail with auth issues, which triggers another auth check, which can trigger another recovery leading to this loop. There's a couple related issues:
- If we start in the
Connectedstate, and CheckAuthorizationStatus doesn't fail, then we consider it a recovery when that's not necessarily true. We could stop doing this, but there are cases where it's good. For example, we try to fetch a profile, fail with a invalid access code, go throughCheckAuthorizationStatusand get a good access code. At this point we do want to try to fetch the profile again. - Auth issues are not the only thing we want to recover from. What about network errors when fetching the profile/device constellation state? Once we get the network back online, it seems like we still want to try to refetch.
I think we should update what triggers the accountAuthenticated notification:
- The transition AuthIssues -> Connected triggers it
- Connected -> Connected doesn't (i.e. if the you're connected and the CheckAuthorizationStatus event doesn't fail, that doesn't count as "auth recovery").
- If the profile or device constellation data is missing, we retry fetching them on a schedule.
- Maybe we refetch on a slower schedule even if we have that data. There's always the chance that our data is out-of-date.
| Reporter | ||
Comment 3•20 days ago
|
||
I checked out the android code and it's roughly doing the same thing, but also has a check so that it only sends the onAuthenticated notification on the AuthIssues -> Connected transition. Maybe that's the first thing we can do.
| Reporter | ||
Comment 4•20 days ago
|
||
- The transition AuthIssues -> Connected triggers it
I'm not even sure this should trigger a refetching the profile and device list. As Mark points out, we already have code to do that inside get_profile, so it might not be bringing any benefit. Maybe we should be doing more of that and not having the application re-trigger the get_profile calls (at least in response to state changes, a timer could still make sense)
| Reporter | ||
Comment 5•19 days ago
|
||
The transition AuthIssues -> Connected triggers it
I just realized that we should only be doing this transition after an OAuth flow (https://bugzilla.mozilla.org/show_bug.cgi?id=2092911) and we do want to trigger the auth recovery code in that case.
| Reporter | ||
Comment 6•10 days ago
|
||
Going back to the circuit breaking solution:
- We already have a check for this
- If we hit the circuit breaker, then I don't think we need to transition to
AuthIssues. It's probably better to just ignore the request since the previous checks either already made a transition or were all inconclusive.
Description
•