From 4941490233a728bc7c64fa80a53d15f772a1219f Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 11 Dec 2025 11:57:36 +0000 Subject: sync: add sync_base_backoff_secs config for better testing --- src/sync/relay_connection.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/sync/relay_connection.rs') diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs index 4f26779..9a580d2 100644 --- a/src/sync/relay_connection.rs +++ b/src/sync/relay_connection.rs @@ -60,6 +60,9 @@ impl RelayConnection { /// /// # Arguments /// * `since` - Optional timestamp for incremental sync on reconnect + /// * `connection_timeout_secs` - Timeout for the connection attempt in seconds. + /// Should be no larger than base_backoff_secs to ensure the connection attempt + /// completes before the next retry would be scheduled. /// /// # Returns /// * `Ok(SubscriptionId)` - The subscription ID on successful connection @@ -67,6 +70,7 @@ impl RelayConnection { pub async fn connect_and_subscribe( &self, since: Option, + connection_timeout_secs: u64, ) -> Result { // Add relay to client self.client @@ -83,13 +87,13 @@ impl RelayConnection { // // Using try_connect_relay gives us: // 1. Immediate error return on connection failure - // 2. Configurable timeout (5 seconds default) + // 2. Configurable timeout (set to base_backoff_secs to ensure retry timing works) // 3. No conflicting retry logic (we use HealthTracker for backoff) // 4. Cleaner error messages for metrics recording // // See: nostr-sdk-0.44 Client::try_connect_relay documentation self.client - .try_connect_relay(&self.url, std::time::Duration::from_secs(5)) + .try_connect_relay(&self.url, std::time::Duration::from_secs(connection_timeout_secs)) .await .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?; -- cgit v1.2.3