Fix hang on sign-up

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 <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-10-22 14:46:04 -07:00
parent fe09f9da99
commit 9dfd338077
2 changed files with 9 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import Network
struct RelayHandler { struct RelayHandler {
let sub_id: String 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 filters: [NostrFilter]?
let to: [RelayURL]? let to: [RelayURL]?
var handler: AsyncStream<(RelayURL, NostrConnectionEvent)>.Continuation var handler: AsyncStream<(RelayURL, NostrConnectionEvent)>.Continuation
@@ -535,7 +536,10 @@ actor RelayPool {
} }
for handler in handlers { 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)") logStreamPipelineStats("RelayPool_\(relay_id.absoluteString)", "RelayPool_Handler_\(handler.sub_id)")
handler.handler.yield((relay_id, event)) handler.handler.yield((relay_id, event))
} }

View File

@@ -143,8 +143,12 @@ struct SaveKeysView: View {
for relay in bootstrap_relays { for relay in bootstrap_relays {
await add_rw_relay(self.pool, relay) await add_rw_relay(self.pool, relay)
} }
self.loading = true
Task { Task {
await self.pool.connect()
let stream = AsyncStream<(RelayURL, NostrConnectionEvent)> { streamContinuation in let stream = AsyncStream<(RelayURL, NostrConnectionEvent)> { streamContinuation in
Task { await self.pool.register_handler(sub_id: "signup", filters: nil, handler: streamContinuation) } 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) 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) { func save_to_storage(first_contact_event: NdbNote, first_relay_list_event: NdbNote, for account: CreateAccountModel) {