From a31f6bce0e82454af54415c5364e7d1286c45e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Mon, 3 Nov 2025 15:01:14 -0800 Subject: [PATCH] Fix foreground crash caused by a race condition on ProfileModel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `seen_event` set was not isolated, which lead to occasional race conditions between different actors accessing it simultaneously, leading to crashes. Closes: https://github.com/damus-io/damus/issues/3311 Changelog-Fixed: Fixed an occasional random crash related to viewing profiles Signed-off-by: Daniel D’Aquino --- damus/Features/Profile/Models/ProfileModel.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/damus/Features/Profile/Models/ProfileModel.swift b/damus/Features/Profile/Models/ProfileModel.swift index dae8ea95..309d98c9 100644 --- a/damus/Features/Profile/Models/ProfileModel.swift +++ b/damus/Features/Profile/Models/ProfileModel.swift @@ -29,6 +29,7 @@ class ProfileModel: ObservableObject, Equatable { let pubkey: Pubkey let damus: DamusState + @MainActor // Isolate this to the main actor to avoid crashes arising from race conditions var seen_event: Set = Set() var findRelaysListener: Task? = nil @@ -115,8 +116,8 @@ class ProfileModel: ObservableObject, Equatable { let conversations_filter_us = NostrFilter(kinds: conversation_kinds, pubkeys: [pubkey], limit: limit, authors: [damus.pubkey]) print("subscribing to conversation events from and to profile \(pubkey)") for await noteLender in self.damus.nostrNetwork.reader.streamIndefinitely(filters: [conversations_filter_them, conversations_filter_us]) { - try? noteLender.borrow { ev in - if !seen_event.contains(ev.id) { + try? await noteLender.borrow { ev in + if await !seen_event.contains(ev.id) { let event = ev.toOwned() Task { await self.add_event(event) } conversation_events.insert(ev.id)