-
-
Notifications
You must be signed in to change notification settings - Fork 727
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
iOS Concurrent modification exception when closing a scope #2058
Comments
Do you have some code to reproduce? We can contact touchlab team for stately collection 👍 |
The behaviour is expected, if you use an iterator it will detect modification while iterating. Since iteration works by multiple method calls a "safe" collection that wraps access to the methods with reentrant locks does not work to prevent this. Also note that Stately locks (as e.g. The simple fix is to copy the values you want to an array before iterating, as done in e.g. koin/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt Line 61 in c815cc6
contrast with the method in the stacktrace above : koin/projects/core/koin-core/src/commonMain/kotlin/org/koin/core/registry/InstanceRegistry.kt Line 156 in c815cc6
Similar bugfix with test in our own project: |
Yeah the JVM magic is not helping much on iOS world |
Will publish a new 4.0.2-RC2. Will be happy to have feedback 👍 |
Our iOS application occasionally crashes with
ConcurrentModificationException
.Methods like
createAllEagerInstances
andclose
inInstanceRegistry
can cause concurrent mutation because using an iterator over a collection will cause an exception even ifConcurrentMutableMap
was used. We assume that reimplementing access to_instances
in a way similar tocreateAllEagerInstances
(in the same file) should solve the problem.Koin module and version:
koin-core:3.5.6
The text was updated successfully, but these errors were encountered: