Retry requests if storage (auth + credentials) is not ready#6183
Conversation
- add explicit globals to improve intellisense in vscode
move isReady to canMakeRequest
(let the http request logout if the auth token is expired or inexistent)
Co-authored-by: Marc Glasser <marc.aaron.glasser@gmail.com>
Co-authored-by: Marc Glasser <marc.aaron.glasser@gmail.com>
Co-authored-by: Marc Glasser <marc.aaron.glasser@gmail.com>
Co-authored-by: Marc Glasser <marc.aaron.glasser@gmail.com>
enhanceParameters and its related canMakeRequest call
move StoreNetworkTest to NetworkTest
and update unit test
nickmurray47
left a comment
There was a problem hiding this comment.
The changes lgtm afaict - looks like there's one linting issue and also wondering if we can add manual tests for regressions to make sure we aren't breaking anything.
Hmm I don't think so, because the |
Yeah I was thinking that when you sign out the storage is cleared so the values for But since we "cache-first" there's no way for an |
change unit test comments to GIVE-WHEN-THEN format
marcaaron
left a comment
There was a problem hiding this comment.
LGTM 👍
It would be nice to see if the test can be improved further, but maybe not crucial to do right now. I think what we've come up works OK for now.
| * @param {Object} personalDetails | ||
| * @param {String} searchValue | ||
| * @param {Array<String>} betas | ||
| * @param {Array<String>=} betas |
|
Maybe merging main will fix the e2e test or we can restart it. |
Yeah, hopefully, we can improve later this test (which I think we'll require a few changes in And given the importance of
I added another commit with more comments in the unit test and now the e2e test passed 😄 |
|
Left a follow up comment about the JS doc, but I think this is good to merge. |
This reverts commit ec2ee08.
|
Not sure if tests failing had anything to do with the recent change but restarted them to see if they'll pass again |
nickmurray47
left a comment
There was a problem hiding this comment.
Tests pass now! Feel free to merge and @marcochavezf do you mind adding these QA steps to the PR from this comment:
- Mess up the
authTokenand make sure you are reauthenticated - Mess up the
credentialsandauthTokenand make sure you are logged out
Conflicts: src/libs/Network.js
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by @marcaaron in version: 1.1.14-5 🚀
|
|
@marcaaron @marcochavezf Hello! I'm not sure if were testing this correctly. What I did was:
After that, I was not logged out and it looked like I was logged in as the user I randomly wrote on the email |
Ah from the app side I think this is fine because we're only verifying that |
|
🚀 Deployed to production by @AndrewGable in version: 1.1.15-15 🚀
|



cc @marcaaron @tgolen
Details
There's an issue on Android where the user is logged out randomly. We're not 100% sure about the root cause, but one possibility is the existence of a race condition between the async storage and the networks requests; where the auth token and credentials are not read yet from persistent storage (Onyx) while a network request is made.
I was able to reproduce this scenario by adding a
setTimeoutin theOnyx.connectcallback (more details in this comment):Screen.Recording.2021-10-12.at.18.32.38.mov
There's a long discussion in the issue, where different approaches are discussed (both big and small changes). But we agreed on tackling the issue atm without changing the architecture of the Network Queue. This solution is comprised of the following points:
StoreNetworkTest.js) that simulates the scenario where auth token + credentials are not ready.isReadyand its setter toNetwork.jsto process requests only if auth token + credentials are already read from storage, otherwise re-queue the requests to retry later (as long as the request don't have the propertydoNotRetry= true). Also, log a message to the server when this scenario happens.enhanceParameters(which isaddDefaultValuesToParametersinAPI.js), since we're already handling that auth token + credentials are read first and the http request should logout the user if the auth token is inexistent or expired (server should return a 407jsonCodeif we are online). Also, theAPI.jshas changed a lot since the logout (redirectToSignIn()) was added and probably is no longer needed because that's already handled inhandleExpiredAuthToken.Also a few extra comments:
LoginNetworkI disabled the eslint circular dependency warning (hopefully we can fix this later with a better dependency or another design).Onyx.initandOnyx.clearin some tests, because for some reason theOnyx.connectcallback was not triggered and those tests were failing.Fixed Issues
$ #5619
Tests / QA Steps
In Chrome devtools go to Application -> Local Storage and:
authToken(session) and make sure you are reauthenticated.credentialsandauthTokenand make sure you are logged out.N/A
Tested On
Screenshots
N/A