-
-
Notifications
You must be signed in to change notification settings - Fork 732
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
ScopeRegistry.closeAllScopes() causes ConcurrentModificationException for iOS on Kotlin 1.9.20 #1711
Comments
This also impacts |
I can see this as far back as Koin 3.1.x (which is the earliest I checked) when using Kotlin 1.9.20. I think that makes a good argument for this being a Kotlin regression, but I haven't tested against other Kotlin versions. I just came across it when updating an old project from Kotlin 1.5.x |
The Koin iOS implementation uses the kotlin 'HashMap' on iOS (android uses the Java 'ConcurrentHashMap') . Before that didn't crash, and while it's not great that it does now, this is more in line with what a regular Java 'HashMap' would do. So I get why JetBrains made this change. The solution is fairly simple: either make a custom 'ConcurrentHashMap' for Koin, or just copy the map into a local var on 'closeAllScopes()' and loop over that. |
fwiw, the problem persists on Kotlin 1.9.21 |
Thanks for the feedback. I see the PR |
see linked PR #1799 |
Describe the bug
After upgrading to Kotlin 1.9.20,
stopKoin()
causes aConcurrentModificationException
on iOS when multiple scopes are added.This is because stopKoin calls
closeAllScopes
iterates over alls scopes and callsscope.close()
which calls_koin.scopeRegistry.deleteScope(this)
which modifies the hashmap being iterated over.Only seeing this problem on iOS and only as of Kotlin 1.9.20 so I suspect something changed on the expect/actuals of the Hashmap there. Regardless, this should not crash
To Reproduce
On iOS, create a few custom scopes and then stop Koin.
Expected behavior
StopKoin should close all scopes without issue
Koin module and version:
koin-core:3.5.0
(also confirmed on 3.5.2-RC1)Snippet or Sample project to help reproduce
throws
The text was updated successfully, but these errors were encountered: