test(redundancy): lock in stale-Terminated guard + clarify OnTerminated (code-review)

This commit is contained in:
Joseph Doherty
2026-06-15 13:29:58 -04:00
parent 70e6d3d2c0
commit 5a064e086d
2 changed files with 62 additions and 6 deletions
@@ -108,12 +108,15 @@ public sealed class PeerProbeSupervisor : ReceiveActor
/// <param name="t">The termination notice for the dead child.</param>
private void OnTerminated(Terminated t)
{
var dead = _children.FirstOrDefault(kvp => kvp.Value.Equals(t.ActorRef));
if (!dead.Equals(default(KeyValuePair<NodeId, IActorRef>)) && dead.Value is not null)
{
_children.Remove(dead.Key);
_log.Debug("PeerProbeSupervisor: pruned terminated child for peer {Peer}", dead.Key);
}
var entry = _children.FirstOrDefault(kvp => kvp.Value.Equals(t.ActorRef));
// No-match yields Value == null because IActorRef is a reference type. A null here means the
// terminated ref isn't our CURRENT child for any peer — either it was already pruned in
// OnSnapshot (deliberate stop pre-removes from _children), or it's a stale old-generation
// child whose peer has since been re-spawned with a fresh child. Either way: no-op, so we
// never evict the fresh same-peer child on a stale Terminated.
if (entry.Value is null) return;
_children.Remove(entry.Key);
_log.Debug("PeerProbeSupervisor: pruned terminated child for peer {Peer}", entry.Key);
}
/// <summary>