Skip to content

Commit

Permalink
pool: fix send_event_to incorrect timeout error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DanConwayDev committed Mar 26, 2024
1 parent 4d15fe5 commit 814d7e2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crates/nostr-relay-pool/src/relay/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<EventId> = HashSet::new();
let mut not_published: HashMap<EventId, String> = HashMap::new();
let mut notifications = self.internal_notification_sender.subscribe();
Expand Down Expand Up @@ -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> {
Expand Down

0 comments on commit 814d7e2

Please sign in to comment.