Skip to content

Conversation

@arnaudgiuliani
Copy link
Member

Following up to #2234
Safer ScopeFactory, protect all operations from parallel calls

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 HashMap with KoinPlatformTools.safeHashMap() for thread-safe storage
  • Added synchronized blocks around all operations that access or modify the shared values map
  • Improved dropAll() to properly invoke onClose callbacks for all instances before clearing
  • Refactored create() and get() methods to eliminate throwing MissingScopeValueException in favor of creating instances on-demand

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…stance/ScopedInstanceFactory.kt

Co-authored-by: Copilot <[email protected]>
@arnaudgiuliani arnaudgiuliani merged commit e08d5c2 into 4.2.0 Dec 2, 2025
@arnaudgiuliani arnaudgiuliani deleted the fix_scope_factory branch December 2, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants