Skip to content

Commit dfc7c05

Browse files
committed
Squashed commit of the following:
commit ab80dfa Author: xdustinface <xdustinfacex@gmail.com> Date: Fri Feb 13 01:45:26 2026 +0100 fix: use `Interval` for maintenance tick and delay the first dns tick `time::sleep(MAINTENANCE_INTERVAL)` creates a fresh future on each `tokio::select!` loop iteration. Since `time::interval().tick()` fires immediately on the first poll, the DNS branch completes first and the maintenance sleep is dropped before awaiting. With `MAINTENANCE_INTERVAL` and `DNS_DISCOVERY_DELAY` both at 10 seconds, maintenance_tick will never execute in non-exclusive mode.
1 parent 54a5380 commit dfc7c05

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

dash-spv/src/network/manager.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use dashcore::network::message_headers2::CompressionState;
3333
use dashcore::prelude::CoreBlockHeight;
3434
use dashcore::Network;
3535
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
36+
use tokio::time::Instant;
3637
use tokio_util::sync::CancellationToken;
3738

3839
const DEFAULT_NETWORK_EVENT_CAPACITY: usize = 10000;
@@ -902,11 +903,14 @@ impl PeerNetworkManager {
902903
let mut tasks = self.tasks.lock().await;
903904
tasks.spawn(async move {
904905
// Periodic DNS discovery check (only active in non-exclusive mode)
905-
let mut dns_interval = time::interval(DNS_DISCOVERY_DELAY);
906+
let mut dns_interval =
907+
time::interval_at(Instant::now() + DNS_DISCOVERY_DELAY, DNS_DISCOVERY_DELAY);
908+
// Periodic reconnection check (active in both modes)
909+
let mut maintenance_interval = time::interval(MAINTENANCE_INTERVAL);
906910

907911
while !this.shutdown_token.is_cancelled() {
908912
tokio::select! {
909-
_ = time::sleep(MAINTENANCE_INTERVAL) => {
913+
_ = maintenance_interval.tick() => {
910914
log::debug!("Maintenance interval elapsed");
911915
this.maintenance_tick().await;
912916
}

0 commit comments

Comments
 (0)