fixing concurrent dispatch crash by using copy on write set

- whilst closing the session, we iterate through all the listeners calling onSessionStopped however some implementations also use this callback to remove themselves from the listeners, causing the concurrent modification crash
This commit is contained in:
Adam Brown 2022-06-22 10:41:05 +01:00
parent a8cd6ca497
commit 23cd6dae42
2 changed files with 3 additions and 1 deletions

1
changelog.d/5821.bugfix Normal file
View file

@ -0,0 +1 @@
Fixes concurrent modification crash when signing out or launching the app

View file

@ -19,12 +19,13 @@ package org.matrix.android.sdk.internal.session
import org.matrix.android.sdk.api.extensions.tryOrNull
import org.matrix.android.sdk.api.session.Session
import timber.log.Timber
import java.util.concurrent.CopyOnWriteArraySet
import javax.inject.Inject
@SessionScope
internal class SessionListeners @Inject constructor() {
private val listeners = mutableSetOf<Session.Listener>()
private val listeners = CopyOnWriteArraySet<Session.Listener>()
fun addListener(listener: Session.Listener) {
synchronized(listeners) {