Skip to content
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

workaround ConcurrentModificationException when closeAllScopes in js #2032

Conversation

luozejiaqun
Copy link

Fixes gh-1963

@luozejiaqun luozejiaqun force-pushed the bugfix/closeScopeConcurrentError branch from 515352f to f649e59 Compare October 25, 2024 01:29
@arnaudgiuliani
Copy link
Member

can you propose something else? it seems a bit weird here to do that 🤔

@luozejiaqun
Copy link
Author

@arnaudgiuliani just as i mentioned in #1963 , directly calling scopes.toList() on the JS platform is ineffective because it doesn't create a new list. Therefore, we need to explicitly create a separate list.

@arnaudgiuliani arnaudgiuliani added this to the 4.1 milestone Nov 15, 2024
@arnaudgiuliani arnaudgiuliani modified the milestones: 4.1.0, 4.0.2 Jan 9, 2025
@arnaudgiuliani
Copy link
Member

arnaudgiuliani commented Jan 9, 2025

@luozejiaqun we could test fix with provided snippet. Seems same access problem as: #2058

@@ -90,7 +90,9 @@ class ScopeRegistry(private val _koin: Koin) {
}

private fun closeAllScopes() {
_scopes.values.toList().forEach { scope ->
// use another list to workaround ConcurrentModificationException
val scopes = List(_scopes.values.size) { _scopes.values.elementAt(it) }
Copy link
Member

Choose a reason for hiding this comment

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

This could work too:

_scopes.values.toTypedArray().forEach { scope ->
            scope.close()
        }

@arnaudgiuliani
Copy link
Member

Let's see how 4.0.2-RC2 is going. Else let's reopen it 👍

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.

ScopeRegistry.closeAllScopes() causes ConcurrentModificationException for JS
2 participants