amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

DataStore doesn't emit `ready` event.

Open anatomybook opened this issue 3 years ago • 3 comments

Describe the bug

Essentially, I'd like to reopen https://github.com/aws-amplify/amplify-ios/issues/1302. Everything is described there.

I can reproduce that the ready event doesn't get emitted unless I re-introduce my old hack, that I published here.

Steps To Reproduce

Steps to reproduce the behavior:
1. Delete App to ensure sync from scratch
2. Run App, triggering initial sync
3. Observe items syncing
4. Observe no more syncing activity, while `ready` not having been emitted

Expected behavior

I expect DataStore to reliably emit the signal.

Amplify Framework Version

1.26.1

Amplify Categories

DataStore

Dependency manager

Cocoapods

Swift version

swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)

CLI version

8.2.0

Xcode version

Xcode 13.3.1, Build version 13E500a

Relevant log output

No response

Is this a regression?

Yes

Regression additional context

No response

Device

Simulator

iOS Version

15.4

Specific to simulators

haven't tried

Additional context

No response

anatomybook avatar Jun 05 '22 07:06 anatomybook

Hi @anatomybook, for the code snippet from https://github.com/aws-amplify/amplify-ios/issues/1302#issuecomment-906404001

if reconciledReceived == recordsReceived {
   dispatchModelSyncedEvent()
}
else {
    initialSyncOperationFinished = true
}

within onReceiveSyncOperationEvent. Both onReceiveSyncOperationEvent and onReceiveReconciliationEvent will be called in parallel multiple times as the sync operation retrieves more pages of items while the reconciliation applies the mutations. I think your code snippet makes sense because if there is a delay in receiving the finished event from the sync operation, and is emitted after the last reconciled event then the modelSynced event will never get emitted. It won't get emitted because no more items get reconciled to trigger the check, so adding the check in the finished event of the sync process would make sure the event is emitted.

lawmicha avatar Jul 08 '22 21:07 lawmicha

Thanks for bringing this to our attention @anatomybook , I added the PR https://github.com/aws-amplify/amplify-ios/pull/1989 with your code change here.

lawmicha avatar Jul 08 '22 21:07 lawmicha

Thanks for considering my proposal.

anatomybook avatar Aug 07 '22 14:08 anatomybook

this was merged in 1.28.0

lawmicha avatar Oct 21 '22 13:10 lawmicha

I'm still seeing this issue more often than not. I'm using version 2.1.0 of amplify-swift. I always see the log output [AWSDataStorePlugin] [Lifecycle event 6]: ready but way more often than not, the event doesn't come through the hub's datastore channel.

ynnadrules avatar Nov 11 '22 19:11 ynnadrules