Safer ScopeFactory, protect all operations from parallel calls#2323
Merged
arnaudgiuliani merged 2 commits into4.2.0from Dec 2, 2025
Merged
Safer ScopeFactory, protect all operations from parallel calls#2323arnaudgiuliani merged 2 commits into4.2.0from
arnaudgiuliani merged 2 commits into4.2.0from
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enhances thread-safety in the ScopedInstanceFactory class by adding comprehensive synchronization to protect all operations from parallel calls. This is a follow-up to PR #2234, focusing specifically on making the scoped instance factory fully thread-safe.
Key changes:
- Replaced standard
HashMapwithKoinPlatformTools.safeHashMap()for thread-safe storage - Added
synchronizedblocks around all operations that access or modify the sharedvaluesmap - Improved
dropAll()to properly invokeonClosecallbacks for all instances before clearing - Refactored
create()andget()methods to eliminate throwingMissingScopeValueExceptionin favor of creating instances on-demand
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
projects/core/koin-core/src/commonMain/kotlin/org/koin/core/instance/ScopedInstanceFactory.kt
Outdated
Show resolved
Hide resolved
projects/core/koin-core/src/commonMain/kotlin/org/koin/core/instance/ScopedInstanceFactory.kt
Show resolved
Hide resolved
…stance/ScopedInstanceFactory.kt Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following up to #2234
Safer ScopeFactory, protect all operations from parallel calls