Closed mhyassin closed 11 months ago
Hi @mhyassin can you run the Amplify CLI command amplify diagnose --send-report
and share the project identifier that is output? This will give us some insight into your GraphQL schema and API configuration so we can attempt to reproduce the issue.
Since this error seems to happen intermittently, could you check to see if there are any mutations being sent or pending mutations in the outbox when signing out?
You can try enabling the Amplify logger by adding this line under the Amplify configuration
Amplify.Logger.LOG_LEVEL="DEBUG";
Or you should be able to use the Hub to listen to datastore events and log them to gain some more insight into what it's trying to do during sign out.
Hi @chrisbonifacio, The project identifier is: 1f41c9d6304e82061193f8ee2e85ae0a
Hi @mhyassin! Were you able to debug with any of @chrisbonifacio's suggestions (i.e. checking for the existence of pending mutations and / or debugging with additional logging)?
Hey @david-mcafee, I tried debugging for some time, I'm sharing my findings below,
Here is the full logout leading to the issue
p.s.: not sure if it is related but sometimes it just hangs on LOG [DEBUG] 43:48.175 AWSAppSyncRealTimeProvider - closing WebSocket...
forever
// gets called when the user taps on the logout button
export const signout = async () => {
await resetApp();
try {
await Auth.signOut();
} catch (err) {
Alert.alert('Logout failed.');
}
};
export async function resetApp() {
await DataStore.clear();
}
I've managed to hugly decrease the number of occurances by moving the DataStore.clear()
to the auth hub listener by doing this (but it still happens):
useEffect(() => {
checkUser();
/** Hub listener callback */
const hubListener: HubCallback = (capsule) => {
// federatedSignIn triggers auth events
const event = capsule.payload.event;
switch (event) {
case 'signIn':
case 'cognitoHostedUI':
DataStore.clear().then(() => {
checkUser();
});
break;
default:
break;
}
};
return Hub.listen('auth', hubListener);
}, []);
There is also another issue that happens alot in sentry, I was not able to reproduce myself to be honest and I'm not sure if it is related
@mhyassin looking at the logs you provided, it looks like a mutation occurs after the sync engine has stopped. Is it possible that somewhere you are attempting to perform a mutation after calling DataStore.clear
? If so, there would be a race condition happening between the mutation and the attempt to clear DataStore.
Also, instead of listening for cognitoHostedUI
prior to calling DataStore.clear
(as you do in the code sample you provided), I'd recommend waiting for the signOut
event from the Auth category before calling DataStore.clear
. This is explained in our documentation, but I've also included a code snippet below:
Hub.listen('auth', async (data) => {
if (data.payload.event === 'signOut') {
await DataStore.clear();
}
});
@mhyassin, did you get a chance to see the question and comment above?
@cwomack Yeah, I did, I was giving it sometime to check Sentry, moving DataStore.clear()
to the signOut
event helped a lot, thanks @david-mcafee
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
Authentication, Analytics, GraphQL API, DataStore, Storage
Amplify Categories
No response
Environment information
Describe the bug
We call DataStore.clear() while the user is signing out and some times after calling
await DataStore.clear()
I get this type error, not sure if it affects anything thoughExpected behavior
The promise rejection is handled correctly
Reproduction steps
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response