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:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user