Terminate file sync if connecting peers too long (#136)

This commit is contained in:
Bo QIU 2024-07-27 21:05:44 +08:00 committed by GitHub
parent 7d73ccd1e1
commit ae9c52c0e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -126,7 +126,7 @@ impl Batcher {
Ok(Some(SyncResult::Failed)) Ok(Some(SyncResult::Failed))
} }
// file sync timeout // finding peers timeout
Some(SyncState::FindingPeers { origin, .. }) Some(SyncState::FindingPeers { origin, .. })
if origin.elapsed() > self.config.find_peer_timeout => if origin.elapsed() > self.config.find_peer_timeout =>
{ {
@ -135,6 +135,15 @@ impl Batcher {
Ok(Some(SyncResult::Timeout)) 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 // others
_ => Ok(None), _ => Ok(None),
} }

View File

@ -40,6 +40,7 @@ pub enum SyncState {
}, },
FoundPeers, FoundPeers,
ConnectingPeers { ConnectingPeers {
origin: InstantWrapper,
since: InstantWrapper, since: InstantWrapper,
}, },
AwaitingOutgoingConnection { AwaitingOutgoingConnection {
@ -253,6 +254,7 @@ impl SerialSyncController {
info!(%self.tx_seq, %num_peers_dailed, "Connecting peers"); info!(%self.tx_seq, %num_peers_dailed, "Connecting peers");
self.state = SyncState::ConnectingPeers { self.state = SyncState::ConnectingPeers {
origin: self.since,
since: Instant::now().into(), since: Instant::now().into(),
}; };
} }
@ -632,6 +634,7 @@ impl SerialSyncController {
SyncState::FoundPeers => { SyncState::FoundPeers => {
if self.peers.all_shards_available(vec![Connecting, Connected]) { if self.peers.all_shards_available(vec![Connecting, Connected]) {
self.state = SyncState::ConnectingPeers { self.state = SyncState::ConnectingPeers {
origin: self.since,
since: Instant::now().into(), since: Instant::now().into(),
}; };
} else { } else {