Skip to content

Commit

Permalink
Merge pull request #2113 from InsertKoinIO/fix_close_scope
Browse files Browse the repository at this point in the history
Fix Scope closing concurrent access
  • Loading branch information
arnaudgiuliani authored Jan 9, 2025
2 parents 32095b4 + ace7d02 commit f28a59d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.koin.core.qualifier.Qualifier
import org.koin.core.scope.Scope
import org.koin.core.scope.ScopeID
import org.koin.mp.KoinPlatformTools.safeHashMap
import kotlin.collections.toTypedArray
import kotlin.reflect.KClass

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -159,13 +160,13 @@ class InstanceRegistry(val _koin: Koin) {
}

internal fun dropScopeInstances(scope: Scope) {
_instances.values.filterIsInstance<ScopedInstanceFactory<*>>().forEach { factory -> factory.drop(scope) }
val factories = _instances.values.toTypedArray()
factories.filterIsInstance<ScopedInstanceFactory<*>>().forEach { factory -> factory.drop(scope) }
}

internal fun close() {
_instances.forEach { (_, factory) ->
factory.dropAll()
}
val factories = _instances.values.toTypedArray()
factories.forEach { factory -> factory.dropAll() }
_instances.clear()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ScopeRegistry(private val _koin: Koin) {
}

private fun closeAllScopes() {
_scopes.values.toList().forEach { scope ->
_scopes.values.toTypedArray().forEach { scope ->
scope.close()
}
}
Expand Down

0 comments on commit f28a59d

Please sign in to comment.