From 814d7e2e21664a38ccc50b5ff1f8e5035bc661ff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 26 Mar 2024 13:31:07 +0000 Subject: [PATCH] pool: fix send_event_to incorrect timeout error immedately listen for OK msgs when events are sent using batch_events. prevents the OK msg from being missed, causing the to eventually fail through timeout when the msg was successfully recieved by relays. --- crates/nostr-relay-pool/src/relay/internal.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/nostr-relay-pool/src/relay/internal.rs b/crates/nostr-relay-pool/src/relay/internal.rs index a87fa2218..bb82132d1 100644 --- a/crates/nostr-relay-pool/src/relay/internal.rs +++ b/crates/nostr-relay-pool/src/relay/internal.rs @@ -12,6 +12,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::time::Duration; +use async_utility::futures_util::future::{join, join_all}; #[cfg(not(target_arch = "wasm32"))] use async_utility::futures_util::stream::AbortHandle; use async_utility::{futures_util, thread, time}; @@ -1063,10 +1064,10 @@ impl InternalRelay { } // Batch send messages - self.batch_msg(msgs, opts).await?; + let send_batch_msg = self.batch_msg(msgs, opts); // Hanlde responses - time::timeout(Some(opts.timeout), async { + let handle_responses = time::timeout(Some(opts.timeout), async { let mut published: HashSet = HashSet::new(); let mut not_published: HashMap = HashMap::new(); let mut notifications = self.internal_notification_sender.subscribe(); @@ -1121,9 +1122,13 @@ impl InternalRelay { } else { Err(Error::EventsNotPublished(not_published)) } - }) - .await - .ok_or(Error::Timeout)? + }); + + let (send_batch_msg_res, handle_responses_res) = + join(send_batch_msg, handle_responses).await; + + send_batch_msg_res?; + handle_responses_res.ok_or(Error::Timeout)? } async fn resubscribe_all(&self, opts: RelaySendOptions) -> Result<(), Error> {