fix: stop the previous peer actor when re-registering a username

register_peer inserted the new handle and silently dropped the old one, leaving
the previous actor running as an orphan that pins a thread-pool worker forever;
its later shutdown could also remove the replacement connection from the
registry. The displaced actor is now told to stop.
This commit is contained in:
michel
2026-07-18 14:37:35 +02:00
parent c5f57cccea
commit 15ac923bd9
+11 -1
View File
@@ -49,7 +49,17 @@ impl PeerRegistry {
.peers .peers
.lock_safe() .lock_safe()
.map_err(|e| format!("peer registry lock poisoned: {}", e))?; .map_err(|e| format!("peer registry lock poisoned: {}", e))?;
peers.insert(username.clone(), handle.clone()); // Stop any actor already registered under this username so it does not
// become an orphan pinning a pool worker forever (and so its later
// shutdown cannot remove this new connection from the registry).
if let Some(old_handle) = peers.insert(username.clone(), handle.clone())
{
let _ = old_handle.stop();
debug!(
"[peer_registry] Replaced existing peer actor for {}",
username
);
}
Ok(handle) Ok(handle)
} }