From c07202944debb87ab7d43abac6c469ab87c9e0ee Mon Sep 17 00:00:00 2001 From: davotoula Date: Wed, 5 Nov 2025 18:52:40 +0100 Subject: [PATCH] Adjusted subscription cleanup to avoid mutating the watcher map while iterating it, preventing the ConcurrentModificationException when accounts switch --- .../follows/AccountFollowsLoaderSubAssembler.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt index 36fc9474c..87c91c143 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/account/follows/AccountFollowsLoaderSubAssembler.kt @@ -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()