Adjusted subscription cleanup to avoid mutating the watcher map while iterating it, preventing the ConcurrentModificationException when accounts switch

This commit is contained in:
davotoula
2025-11-05 18:52:40 +01:00
parent 178582f3c4
commit c07202944d

View File

@@ -186,11 +186,11 @@ class AccountFollowsLoaderSubAssembler(
}
// removes accounts that are not being subscribed anymore.
accountUpdatesJobMap.forEach {
if (it.key !in uniqueSubscribedAccounts.keys) {
endWatcher(it.key)
}
}
// Cancel watchers for accounts no longer observed using a snapshot to avoid CME
accountUpdatesJobMap.keys
.toList()
.filter { it !in uniqueSubscribedAccounts.keys }
.forEach { endWatcher(it) }
}
private val accountUpdatesJobMap = mutableMapOf<User, Job>()