From 61eb83323976ad1e4f41a750e7adac312efc9540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Sun, 5 Oct 2025 16:52:56 -0700 Subject: [PATCH] Add temporary experimental delay to check hypothesis on occasional init timeline staleness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel D’Aquino --- .../NostrNetworkManager/SubscriptionManager.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/damus/Core/Networking/NostrNetworkManager/SubscriptionManager.swift b/damus/Core/Networking/NostrNetworkManager/SubscriptionManager.swift index 1fdc7ba5..aac1d922 100644 --- a/damus/Core/Networking/NostrNetworkManager/SubscriptionManager.swift +++ b/damus/Core/Networking/NostrNetworkManager/SubscriptionManager.swift @@ -197,6 +197,14 @@ extension NostrNetworkManager { try await Task.sleep(nanoseconds: 1_000_000_000) continue } + + // FIXME: The delay below is to prevent race conditions when the RelayPool is initializing during the app start. + // Without this, occasionally there is a race condition that causes the subscribe call to be missed somehow + // despite mechanisms in place to queue up requests when relays are disconnected, as well as mechanisms to send subscribe requests when the relay is already connected. + // This is difficult to fix as it will require a big refactor in `RelayPool` to implement proper async/await mechanisms, instead of the current "fire and forget" interfaces. + // If this delay fixes the occasional timeline staleness when starting the app, it helps prove the hypothesis above. + try await Task.sleep(nanoseconds: 2_000_000_000) + do { for await item in self.pool.subscribe(filters: filters, to: desiredRelays, id: id) { // NO-OP. Notes will be automatically ingested by NostrDB