-
-
Notifications
You must be signed in to change notification settings - Fork 735
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: race condition when keys are added or removed while the object is being traversed #1062
fix: race condition when keys are added or removed while the object is being traversed #1062
Conversation
Should fix ConcurrentModificationException in parse-community#1061.
@shlusiak Could you give more details about that cost? |
Codecov Report
@@ Coverage Diff @@
## master #1062 +/- ##
============================================
+ Coverage 65.28% 65.29% +0.01%
Complexity 2218 2218
============================================
Files 122 122
Lines 9957 9960 +3
Branches 1337 1337
============================================
+ Hits 6500 6503 +3
Misses 2945 2945
Partials 512 512
Continue to review full report at Codecov.
|
@mtrezza I think @shlusiak refers that because of the new thread-safe approach, on traversal if there are newly added keys they will be missed in this traversal. On next traversal they will be taken in mind. The funny thing is that on Kotlin I faced this issue a lot using coroutines and patch it by trying not to have multiple traversal in same time. |
How does this work technically? Like a read/write queue? |
I will reformat the title to use the proper commit message syntax. |
Thanks for opening this pull request!
|
Fixed merge conflicts. Previously the app could crash if keys are added or removed while the object is being traversed. With this change, at time of traversal a copy of the keyset is created that is traversed instead, fixing the race conditions of concurrent access. This does not resolve other issues of concurrent access, e.g. adding a key while traversal is happening will miss the newly added key, but also removing a key while traversal is happening would see a key where the value does not exist any more ( |
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.
LGTM
@mtrezza may you change the title from
to
|
Ready for merge? |
Can we have the CI running to see the checks passed @mtrezza? |
@shlusiak can you lint the code? |
CONTRIBUTING.md is already updated. If you think it should be rephrased, let me know @mtrezza |
@L3K0V Does |
Ran |
Spotless is widely spread across Java and Kotlin developers. There's standard Meanwhile I will be glad if this and #1058 are merged soon, as they seems to fix a lot of issues. |
Looks good! Thanks for the fix! |
## [2.0.2](2.0.1...2.0.2) (2021-10-17) ### Bug Fixes * race condition when keys are added or removed while the object is being traversed ([#1062](#1062)) ([d28e64d](d28e64d))
🎉 This pull request has been released in version 2.0.2 |
Should fix the
ConcurrentModificationException
in #1061 by creating a local copy before iterating over theParseObject
's keys, with the cost of potentially missing some newly added keys or traversing into anull
value.