-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(datastore): fix observe may receive duplicate events in Android #1339
fix(datastore): fix observe may receive duplicate events in Android #1339
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Does setUpObserve ever need to be called more than once? Should we just reject all subsequent calls?
- This code is not thread-safe. Do we know for sure observe will only ever be called from the main thread or should we add atomics to avoid a race condition?
- If there is an error besides "Failed to start DataStore" on the first setup call, DataStore will never be set up since all other calls will be ignored. Is that the correct behavior? Also, this approach of checking strings is very brittle.
- The PR changes what's sent back with the result (
nil
->true
in iOS, andtrue
/false
in Android), but there is no Dart code in the PR. Are these values handled appropriately already? Does a return offalse
mean something from an error?
The method channel call happens on main thread, and the platform implementation didn't use
I think there is a misunderstanding - "Failed to start DataStore" doesn't cancel the set up, I picked it out here, in order to find a good reason to do However, I think calling
As I described above the value doesn't matter, we could unify both platform implementation. |
I've pushed a new commit (fdf01f6) to use |
Codecov Report
@@ Coverage Diff @@
## main #1339 +/- ##
=======================================
Coverage 47.64% 47.64%
=======================================
Files 234 234
Lines 9899 9899
=======================================
Hits 4716 4716
Misses 5183 5183
Flags with carried forward coverage won't be shown. Click here to find out more. |
...re/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePlugin.kt
Outdated
Show resolved
Hide resolved
createSerializedError(failure) | ||
) | ||
if (failure.message?.contains("Failed to start DataStore", true) == true) { | ||
isSettingUpObserve.set(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the else
clause is triggered, isSettingUpObserve
is never reset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The else
branch is not involved with observe set up, when it falls into the else
it's just forwarding the normal error events into the observe channel. At this moment, the set up has been completed. Doing this all because amplify-android send all type errors to this failure consume...
...ndroid/src/test/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePluginTest.kt
Show resolved
Hide resolved
...re/android/src/main/kotlin/com/amazonaws/amplify/amplify_datastore/AmplifyDataStorePlugin.kt
Outdated
Show resolved
Hide resolved
packages/amplify_datastore/example/ios/unit_tests/DataStorePluginUnitTests.swift
Outdated
Show resolved
Hide resolved
packages/amplify_datastore/example/ios/unit_tests/DataStorePluginUnitTests.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really only had some minor comments. Lgtm otherwise
Issue #, if available:
Description of changes:
flutterResult
call to more appropriate spotsBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.