-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sort out auth token refresh and setCredentials synchronization #101
Sort out auth token refresh and setCredentials synchronization #101
Conversation
5040064
to
96f7d15
Compare
I haven't looked at the code yet, but from reading the description, it looks to me like this is the wrong approach. If calls to setCredentials need to prevail over ongoing updates, instead of waiting for ongoing/queued updates to complete, you should cancel ongoing/queued updates and execute on setCredentials calls immediately. |
On a conceptual level you might have a point, but it turned out to be pretty complex to solve the problem that way, which is why I ended up with this solution. |
|
If i understood correctly, this fix waits for any pending auth calls before applying values passed on I agree this can be further improved to an ideal implementation, but that might mean investing seemingly needless more engineering hours to the problem we would never have. imo, good to look further if thats quick |
We know that this is done by our networking lib anyways. However, it makes sense to switch over to the correct context as early as possible
…refresh is in flight
These are unrelated to the logic, but since they were missed earlier, I took the opportunity to remove them.
Running suspend funs in here using withContextbdDispatchers.IO) now forces us to be able to inject a CoroutineDispatcher, as otherwise tests won't work.
96f7d15
to
08ea6b9
Compare
This fix makes auth networking more robust and predictable. While under normal circumstances the changes added here don't have an effect, making sure our
SharedPreferences
editing is synchronized with backend calls is necessary to enable certain types of UI tests (such as our benchmark tests) to run, assetCredentials
can be called at any time.When calling
setCredential
s, we essentially force credentials to be saved in the auth module's storage.If we do this while a request for token update is in flight, we run the risk that upon return of that request, the credentials you just saved to be overwritten immediately.
This change fixes that by changing how our network calls are synchronized using a
Mutex
:LoginRepository
andTokenRepository
setCredentials
is now synced too, making sure it will wait for all previously issuedgetCredentials
calls to finish.All following calls to
getCredentials
will be based on whatever was saved usingsetCredentials
, so this change effectively prevents accidental overwrites for tests and other automated orchestration.