Skip to content

Commit

Permalink
handle cleanup errors
Browse files Browse the repository at this point in the history
  • Loading branch information
denisu committed Nov 6, 2024
1 parent eddb76b commit 27637c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,13 @@ impl PeerDiscoveryAuthority {
}
}

pub fn cleanup_unreachable_peers(&self) {
pub fn cleanup_unreachable_peers(&self) -> Result<(), rusqlite::Error> {
let conn = self.db_pool.get().unwrap();

conn.execute(
"DELETE FROM peers WHERE is_reachable = 0 AND expires_at <= strftime('%s', 'now')",
[],
)
.unwrap();
)?;
Ok(())
}

pub fn get_reachable_peer_count(&self) -> usize {
Expand Down
8 changes: 5 additions & 3 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use dashmap::DashSet;
use futures::stream::StreamExt;
use std::{net::SocketAddr, sync::Arc};
use tokio::time::{sleep, timeout};
use tracing::{debug, info};
use tracing::{debug, error, info};

#[derive(Clone)]
pub struct PeerProcessor {
Expand Down Expand Up @@ -162,8 +162,6 @@ pub async fn start_peer_rechecker(
authority: Arc<PeerDiscoveryAuthority>,
) -> anyhow::Result<()> {
loop {
authority.cleanup_unreachable_peers();

let expired_peers = authority
.get_expired_reachable_peers(PEER_RECHECK_BATCH_SIZE)
.await;
Expand All @@ -182,6 +180,10 @@ pub async fn start_peer_rechecker(
}
}

if let Err(e) = authority.cleanup_unreachable_peers() {
error!("Failed to cleanup peers: {:?}", e);
}

sleep(PEER_RECHECK_INTERVAL).await;
}
}

0 comments on commit 27637c4

Please sign in to comment.