From 9153a912b0c5951b33c69067ef54644ab8c15bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Wed, 24 Sep 2025 17:55:35 -0700 Subject: [PATCH] Cancel timeout task on stream cancellation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel D’Aquino --- damus/Core/Nostr/RelayPool.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/damus/Core/Nostr/RelayPool.swift b/damus/Core/Nostr/RelayPool.swift index 0d5f0b7d..7be726d6 100644 --- a/damus/Core/Nostr/RelayPool.swift +++ b/damus/Core/Nostr/RelayPool.swift @@ -269,13 +269,22 @@ class RelayPool { } } }, to: desiredRelays) - Task { + let timeoutTask = Task { try? await Task.sleep(for: eoseTimeout) if !eoseSent { continuation.yield(with: .success(.eose)) } } - continuation.onTermination = { @Sendable _ in + continuation.onTermination = { @Sendable termination in + switch termination { + case .finished: + Log.debug("RelayPool subscription %s finished. Closing.", for: .networking, sub_id) + case .cancelled: + Log.debug("RelayPool subscription %s cancelled. Closing.", for: .networking, sub_id) + @unknown default: + break + } self.unsubscribe(sub_id: sub_id, to: desiredRelays) self.remove_handler(sub_id: sub_id) + timeoutTask.cancel() } } }