Closed Daeda88 closed 7 months ago
This also impacts checkModules()
which internally calls koin.close()
and runs through the same closeAllScopes()
logic
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