From ae9c52c0e6e364872a41fc89c34a367cd14f3b3f Mon Sep 17 00:00:00 2001 From: Bo QIU <35757521+boqiu@users.noreply.github.com> Date: Sat, 27 Jul 2024 21:05:44 +0800 Subject: [PATCH] Terminate file sync if connecting peers too long (#136) --- node/sync/src/auto_sync/batcher.rs | 11 ++++++++++- node/sync/src/controllers/serial.rs | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/node/sync/src/auto_sync/batcher.rs b/node/sync/src/auto_sync/batcher.rs index 3e45ac3..847048d 100644 --- a/node/sync/src/auto_sync/batcher.rs +++ b/node/sync/src/auto_sync/batcher.rs @@ -126,7 +126,7 @@ impl Batcher { Ok(Some(SyncResult::Failed)) } - // file sync timeout + // finding peers timeout Some(SyncState::FindingPeers { origin, .. }) if origin.elapsed() > self.config.find_peer_timeout => { @@ -135,6 +135,15 @@ impl Batcher { Ok(Some(SyncResult::Timeout)) } + // connecting peers timeout + Some(SyncState::ConnectingPeers { origin, .. }) + if origin.elapsed() > self.config.find_peer_timeout => + { + debug!(%tx_seq, "Terminate file sync due to connecting peers timeout"); + self.terminate_file_sync(tx_seq, false).await; + Ok(Some(SyncResult::Timeout)) + } + // others _ => Ok(None), } diff --git a/node/sync/src/controllers/serial.rs b/node/sync/src/controllers/serial.rs index 4f94b34..a69aee4 100644 --- a/node/sync/src/controllers/serial.rs +++ b/node/sync/src/controllers/serial.rs @@ -40,6 +40,7 @@ pub enum SyncState { }, FoundPeers, ConnectingPeers { + origin: InstantWrapper, since: InstantWrapper, }, AwaitingOutgoingConnection { @@ -253,6 +254,7 @@ impl SerialSyncController { info!(%self.tx_seq, %num_peers_dailed, "Connecting peers"); self.state = SyncState::ConnectingPeers { + origin: self.since, since: Instant::now().into(), }; } @@ -632,6 +634,7 @@ impl SerialSyncController { SyncState::FoundPeers => { if self.peers.all_shards_available(vec![Connecting, Connected]) { self.state = SyncState::ConnectingPeers { + origin: self.since, since: Instant::now().into(), }; } else {