Skip to content

Commit

Permalink
fix connection disconnect on Client drop
Browse files Browse the repository at this point in the history
  • Loading branch information
Boog900 committed Sep 25, 2024
1 parent 88605b0 commit 14d7cee
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions p2p/p2p-core/src/client/timeout_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ where
CSync: CoreSyncSvc,
PSync: PeerSyncSvc<N>,
{
let connection_tx_weak = connection_tx.downgrade();
drop(connection_tx);

// Instead of tracking the time from last message from the peer and sending a timed sync if this value is too high,
// we just send a timed sync every [TIMEOUT_INTERVAL] seconds.
let mut interval = interval(TIMEOUT_INTERVAL);
Expand All @@ -59,10 +62,10 @@ where

tracing::trace!("timeout monitor tick.");

if connection_tx.is_closed() {
let Some(connection_tx) = connection_tx_weak.upgrade() else {
tracing::debug!("Closing timeout monitor, connection disconnected.");
return Ok(());
}
};

let Ok(permit) = Arc::clone(&semaphore).try_acquire_owned() else {
// If we can't get a permit the connection is currently waiting for a response, so no need to
Expand Down

0 comments on commit 14d7cee

Please sign in to comment.