From 9dfd338077b28dda7f6651d29eb34faac24ae9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Wed, 22 Oct 2025 14:46:04 -0700 Subject: [PATCH] Fix hang on sign-up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a hang during sign-up, which was caused by a change in RelayPool handling code that would only send data to handlers with matching subscription IDs. It so happens that some handlers want to receive all notes, and they set the filters to `nil` to achieve that. Furthermore, some sign-up networking code was moved to prevent race conditions. No changelog entry because the behaviour was not changed since the last public release. Changelog-None Closes: https://github.com/damus-io/damus/issues/3254 Signed-off-by: Daniel D’Aquino --- damus/Core/Nostr/RelayPool.swift | 6 +++++- damus/Features/Onboarding/Views/SaveKeysView.swift | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/damus/Core/Nostr/RelayPool.swift b/damus/Core/Nostr/RelayPool.swift index e44e7ba5..88b3e6c5 100644 --- a/damus/Core/Nostr/RelayPool.swift +++ b/damus/Core/Nostr/RelayPool.swift @@ -10,6 +10,7 @@ import Network struct RelayHandler { let sub_id: String + /// The filters that this handler will handle. Set this to `nil` if you want your handler to receive all events coming from the relays. let filters: [NostrFilter]? let to: [RelayURL]? var handler: AsyncStream<(RelayURL, NostrConnectionEvent)>.Continuation @@ -535,7 +536,10 @@ actor RelayPool { } for handler in handlers { - guard handler.sub_id == event.subId else { continue } + // We send data to the handlers if: + // - the subscription ID matches, or + // - the handler filters is `nil`, which is used in some cases as a blanket "give me all notes" (e.g. during signup) + guard handler.sub_id == event.subId || handler.filters == nil else { continue } logStreamPipelineStats("RelayPool_\(relay_id.absoluteString)", "RelayPool_Handler_\(handler.sub_id)") handler.handler.yield((relay_id, event)) } diff --git a/damus/Features/Onboarding/Views/SaveKeysView.swift b/damus/Features/Onboarding/Views/SaveKeysView.swift index bd142392..468b4c16 100644 --- a/damus/Features/Onboarding/Views/SaveKeysView.swift +++ b/damus/Features/Onboarding/Views/SaveKeysView.swift @@ -143,8 +143,12 @@ struct SaveKeysView: View { for relay in bootstrap_relays { await add_rw_relay(self.pool, relay) } + + self.loading = true Task { + await self.pool.connect() + let stream = AsyncStream<(RelayURL, NostrConnectionEvent)> { streamContinuation in Task { await self.pool.register_handler(sub_id: "signup", filters: nil, handler: streamContinuation) } } @@ -152,10 +156,6 @@ struct SaveKeysView: View { await handle_event(relay: relayUrl, ev: connectionEvent) } } - - self.loading = true - - await self.pool.connect() } func save_to_storage(first_contact_event: NdbNote, first_relay_list_event: NdbNote, for account: CreateAccountModel) {