You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
iOS / Android - After sign out of an account redirects user to resend link page #4595
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open StagingDeployCash deploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:
Identify the pull request that introduced this issue and revert it.
changed the title [-]Android - After sign out of an account redirects user to resend link page[/-][+]iOS / Android - After sign out of an account redirects user to resend link page[/+]on Aug 12, 2021
When we're redirected to sign in we're first setting {authToken: null}
This triggers a change that mounts the PublicScreens and the SiginIn screen
But because we wait for set to complete and only then call Onyx.clear there's a split second where a few connections (withOnyx(SignIn)) are initiated before Onxy.clear runs. One of them is for credentials
Onyx.set informs subscribers optimistically before the actual write to storage complets
With the new LRU cache from the PR we've just reverted the credentials information is still in cache Onyx.connect picks it up just before cache is cleared by Onyx.clear
And even though Onyx.clear does keyChanged(key, null); nearly at the same time
The sendDataToConnection happens last
Since it does a setState on the instance - it overwrites and adds credentials in the component state
With the old connection based cache strategy, we don't have credentials in cache, because there's a brief time where everyone is disconnected from that key. And so the bug does not happen
This looks like to be a problem with Onyx and cache, and might happen with any cache strategy due to how connect works
But it does look like something too rare to worry ATM or have as a priority.
It's seems to be isolated to cases where we're waiting for Onyx.set to complete, and then only if we do something drastic related to storage, like clearing it
// When we clear storage we clear the auth token as well, and are redirected to LoginOnyx.clear().then(()=>{if(preferredLocale){Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE,preferredLocale);}if(errorMessage){Onyx.set(ONYXKEYS.SESSION,{error: errorMessage});}if(activeClients&&activeClients.length>0){Onyx.set(ONYXKEYS.ACTIVE_CLIENTS,activeClients);}});
Or if you worry that something else might preserve the authToken if not explicitly removed
Activity
OSBotify commentedon Aug 12, 2021
👋 Friendly reminder that deploy blockers are time-sensitive ⏱ issues! Check out the open
StagingDeployCashdeploy checklist to see the list of PRs included in this release, then work quickly to do one of the following:MelvinBot commentedon Aug 12, 2021
Triggered auto assignment to @iwiznia (
Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.[-]Android - After sign out of an account redirects user to resend link page[/-][+]iOS / Android - After sign out of an account redirects user to resend link page[/+]iwiznia commentedon Aug 12, 2021
@kidroca is investigating. We suspect #4509 caused this and if so we will probably revert.
Context https://expensify.slack.com/archives/C01GTK53T8Q/p1628776131244300
iwiznia commentedon Aug 12, 2021
Revert PR sent
kidroca commentedon Aug 12, 2021
I think I've found the real issue
The entire storage is cleared on signOut
App/src/libs/actions/SignInRedirect.js
Line 52 in b4cdc79
We have this object defined as the default
accountdataApp/src/components/OnyxProvider.js
Line 19 in b4cdc79
App/src/CONST.js
Line 231 in b4cdc79
here: https://github.com/Expensify/react-native-onyx/blob/073760394ed8d83304beabf227f2c2fb75b3f04f/lib/Onyx.js#L634
and here: https://github.com/Expensify/react-native-onyx/blob/073760394ed8d83304beabf227f2c2fb75b3f04f/lib/Onyx.js#L606
initializeWithDefaultKeyStatesmerges default values with existing data in storageaccountis the exact object shared in step 2) aboveSignInPageApp/src/pages/signin/SignInPage.js
Lines 67 to 71 in b4cdc79
For some reason we still have
props.credentials.loginherewhile
validAccountisundefined(aka falsy)And ultimately we have
truehereApp/src/pages/signin/SignInPage.js
Line 86 in b4cdc79
I'm investigating why we have
props.credentials.logineven after we've cleared storage and cachekidroca commentedon Aug 12, 2021
Ok, this seems to be what's going on:
function redirectToSignIn
App/src/libs/actions/SignInRedirect.js
Lines 50 to 54 in b4cdc79
When we're redirected to sign in we're first setting
{authToken: null}This triggers a change that mounts the
PublicScreensand theSiginInscreenBut because we wait for
setto complete and only then callOnyx.clearthere's a split second where a few connections (withOnyx(SignIn)) are initiated beforeOnxy.clearruns. One of them is forcredentialsOnyx.setinforms subscribers optimistically before the actual write to storage completsWith the new LRU cache from the PR we've just reverted the
credentialsinformation is still in cacheOnyx.connectpicks it up just before cache is cleared byOnyx.clearAnd even though
Onyx.cleardoeskeyChanged(key, null);nearly at the same timeThe sendDataToConnection happens last
Since it does a
setStateon the instance - it overwrites and addscredentialsin the component stateWith the old connection based cache strategy, we don't have
credentialsin cache, because there's a brief time where everyone is disconnected from that key. And so the bug does not happenThis looks like to be a problem with Onyx and cache, and might happen with any cache strategy due to how
connectworksBut it does look like something too rare to worry ATM or have as a priority.
It's seems to be isolated to cases where we're waiting for
Onyx.setto complete, and then only if we do something drastic related to storage, like clearing itkidroca commentedon Aug 12, 2021
As for the bug
It's fixed by rewriting this logic:
App/src/libs/actions/SignInRedirect.js
Lines 48 to 63 in b4cdc79
Like so:
Or if you worry that something else might preserve the
authTokenif not explicitly removed@iwiznia
The bug mentioned on slack, where you briefly see the password input, does not happen with the above proposal
Android.Emulator.-.Pixel_2_API_29_5554.2021-08-12.21-07-17.mp4
It looks like it was caused by the same but the calls happened in different order
iwiznia commentedon Aug 12, 2021
Nice, thanks for the investigation and fix!
iwiznia commentedon Aug 12, 2021
hmmm curious, why did the bug only happen in android?
kidroca commentedon Aug 12, 2021
I thought it happened on both iOS and Android ?
The cause is storage timing, there would be no problem if:
Onyx.sethappens very fast (or is not called at all)isagoico commentedon Aug 12, 2021
Retest on Android was a pass 🎉 Closing the issue.
Beamanator commentedon Sep 10, 2021
@kidroca Is it possible your PR caused this issue? #4971 See investigation by @parasharrajat here: #4971 (comment)
kidroca commentedon Sep 10, 2021
Yes,
Looks like I shouldn't have removed the setting of Auth Token to null
Though the comment mislead me: https://github.com/Expensify/App/pull/4614/files#diff-d27dcfad2dc98cae7cb0f5b5103c607af01dd3ea7a5a234673f5259c5bd158d1L48
I think the proposed solution is ok, and we just need something to trigger the storage event by in other tabs setting a key
AFAIK Onyx.clear should trigger the storage event, not sure why it doesn't...