Open Akash-T2S opened 7 months ago
Hi @Akash-T2S! I have a few follow-up questions to help us better understand the issue:
5.3.6
- have you attempted to upgrade to the latest version of V5 (5.3.16
)?@aws-amplify/datastore-storage-adapter
(2.1.17
)?start
, stop
, or clear
)? If so, could you provide a code snippet demonstrating how, and where, you are calling them?Thank you!
@david-mcafee Thanks for these steps,
Step 1 - has been followed thoroughly and implemented in the same way. Step 2 & 3 - I shall update to the mentioned version and get back. Step 4 - DataStore lifecycle functions are triggered as below
DS Configure:
const configureDataStore = () => {
DataStore.configure({
authProviders: {
functionAuthProvider: async () => {
return {
token: licenseKey
};
}
},
syncExpressions: getSyncExpression(storeId, settingsTimeZone),
syncPageSize: 1000,
maxRecordsToSync: 100000,
fullSyncInterval: FULL_SYNC_INTERVAL,
storageAdapter: SQLiteAdapter,
errorHandler: (error) => {}
});
}
DS Life cycle:
const clearDataStore = async () => {
await DataStore.clear();
};
const stopDataStore = async () => {
await DataStore.stop();
};
const startDataStore = async () => {
await DataStore.start();
};
DS Initialisation:
useEffect(() => {
configureDataStore();
startDataStore();
if (!hubListener) {
hubListener = Hub.listen('datastore', async (hubData) => {
if (event === 'ready') {
const order = await DataStore.query(Order, (c) =>
c.and((c) => [
c.storeId.eq(storeId),
c.deliveryAt.ge(getGraterThanDatesForSyncExpression(settingsTimeZone))
])
);
}
}
}
return () => {
removeOrderSubscription();
removePrinterObjSubscription();
if (isValidElement(hubListener)) {
hubListener();
hubListener = null;
}
if (isValidElement(pubsubListner)) {
pubsubListner();
pubsubListner = null;
}
};
}, []);
@Akash-T2S, can you share any relevant code where you're calling DataStore.clear()
and DataStore.stop
(or based on your code snippets for the DS Lifecycles, clearDataStore
and stopDataStore
respectively?
@cwomack clearDataStore will be called only on logout. Whereas stopDataStore will be called when there is any KeepAliveTimeOut happens (KA acknowledgement is missed) through 'api' channel.
Hub.listen('api', async (data) => {
const { payload } = data;
if (payload?.event === CONNECTION_STATE_CHANGE) {
if (payload?.data?.connectionState === 'ConnectedPendingKeepAlive') {
await DataStore.stop();
await DataStore.start();
}
}
}
@Akash-T2S - it looks like the failure is occurring when you attempt to perform a DataStore operation (e.g. DataStore.query
) while DataStore is still "stopping". To avoid this, you can wait for DataStore to be in a "ready" state (see this section of our docs) before attempting to perform an operation.
Additionally, since DataStore works offline, there shouldn't be a need to stop / start DataStore on connection state changes. Can you help us understand your usecase for stopping / starting DataStore on connection state changes?
Lastly, have you attempted to upgrade to the versions listed in this comment?
@david-mcafee I agree with your point, I make query’s and other operations only when AppSync ready event trigger(after all model synced). Also, I'm trying to stop and start only when the pending keep alive is missed and not when the transition of network status. Even when I don't have that block of code the same issue happens. This reproducible steps are tricky but tbh it occurs more often in the latest version.
Regarding the version update, No luck on that.
@Akash-T2S - thank you for your response! To confirm, are you saying that the issue is still present even when you completely disable all calls to DataStore.stop()
in your app? If you could provide us with more detailed reproduction steps and/or context with regards to how and where you are calling DataStore operations and lifecycle methods, that would help us better understand the issue!
Lastly, you mentioned that you had no luck on updating the Amplify version - can you help us understand the issue so we can assist with unblocking you? Thank you!!
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
DataStore
Amplify Version
v5
Amplify Categories
No response
Backend
None
Environment information
Describe the bug
I have been using Amplify Datastore for the past 2 years and after the update to version 5.x.x I've encountered an issue with intermittent internet connectivity. Whenever there are fluctuations in the network, the networkStatus of the HubListener first reports false and then true. After a full or delta sync, any Datastore action fails and throws errors, rendering Datastore unusable until I refresh the app.
The issue is depend on the next action after the internet fluctuations.
Issue: DataStoreStateError: Tried to execute
DataStore.query()/DataStore.Start()
while DataStore was "Stopping". This can only be done while DataStore is "Started" or "Stopped". To remedy: Ensure all calls tostop()
andclear()
have completed first. If this is not possible, retry the operation until it succeedsOnce internet is back usual delta sync too fails at times. This can be reproduced in both Android & iOS devices
Expected behavior
Datastore operations should perform even after internet fluctuations and should not affect the usage of it.
Reproduction steps
1) Sync models 2) Once AppSync event is ready 3) Pull out the internet cable if Wifi is connected and put back 4) Repeat step 3 twice or thrice 5) Turn off the Wifi and Turn on back 6) Connect back the internet 7) Wait for delta sync to happen 8) Delta sync fails and other operations will also fail
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