P2P: fix connection disconnect on Client drop (#298)
Some checks failed
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
Doc / build (push) Has been cancelled
Doc / deploy (push) Has been cancelled

fix connection disconnect on `Client` drop
This commit is contained in:
Boog900 2024-09-25 20:56:57 +01:00 committed by GitHub
parent 88605b081f
commit a072d44a0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -45,6 +45,9 @@ where
CSync: CoreSyncSvc, CSync: CoreSyncSvc,
PSync: PeerSyncSvc<N>, 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, // 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. // we just send a timed sync every [TIMEOUT_INTERVAL] seconds.
let mut interval = interval(TIMEOUT_INTERVAL); let mut interval = interval(TIMEOUT_INTERVAL);
@ -59,10 +62,10 @@ where
tracing::trace!("timeout monitor tick."); 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."); tracing::debug!("Closing timeout monitor, connection disconnected.");
return Ok(()); return Ok(());
} };
let Ok(permit) = Arc::clone(&semaphore).try_acquire_owned() else { 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 // If we can't get a permit the connection is currently waiting for a response, so no need to