-
Notifications
You must be signed in to change notification settings - Fork 199
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
Bug in documentation #3758
Comments
This definitely is the right place. We will look into the issue and provide an udpate. |
Awesome! 😊 |
@mortenbekditlevsen |
@harsh62 For instance two subsequent updates of a value first from '1' to '2' and the other from '2' to '3'. If both fail, and they both fail in order, then the latter 'roll back' would roll back to '2'. |
Thanks. Our team will look into prioritizing this soon. |
Describe the bug
I'm not certain if this is the correct place to report this, but the Amplify v2 Optimistic UI example at: https://docs.amplify.aws/swift/build-a-backend/data/optimistic-ui/#complete-example
is quite buggy.
It uses an actor to protect mutable state, but it carries values derived from that state across suspension points, introducing bugs that can cause crashes.
For instance the
updateProperty
function reads anindex
and arollbackProperty
, then awaits an API call (allowing other modification of the state to occur, for instance someone deleting all properties).Then after the await, the index is used without re-validating, so in case the
properties
array has a size change, the index can now be invalid.Example that can cause a crash:
createProperty
and thenupdateProperty
with the same property - in an offline situation, so all API calls will failcreateProperty
runs first andproperties
now has a count of 1createProperty
updateProperty
runs and stores the value0
inindex
updateProperty
createProperty
resumes execution, but due to being offline we have an error, and we are removing the item at index 0 of theproperties
array - leaving an empty array. ThecreateProperty
function completesupdateProperty
resumes, also with an error, it attempts to updateproperties
at index 0 which now doesn't exist, and it causes a crash.Steps To Reproduce
Expected behavior
Documentation should not suggest anti-patterns that may cause crashes. :-)
Amplify Framework Version
2
Amplify Categories
API
Dependency manager
Swift PM
Swift version
5.10
CLI version
Xcode version
14.3.1
Relevant log output
Is this a regression?
No
Regression additional context
No response
Platforms
No response
OS Version
iOS 15.3
Device
iPhone 15
Specific to simulators
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: