fix(cluster): leader-auto-down restarts a node its peer has shut out; higher address restarts when both are (#132)
A node frozen past failure detection + StableAfter, or both sides of a partition that heals after each downed the other, used to stay a second active node until an operator restarted one: the peer quarantines the removed UID and Akka.Cluster 1.5.62 never acts on ThisActorSystemQuarantinedEvent. ShutOutRestart (child of the LeaderAutoDown downing actor; opt-out via ScadaBridge:Cluster:LeaderAutoDown:RestartWhenShutOut, default on for leader-auto-down only) watches two signals: - S1 ThisActorSystemQuarantinedEvent: the peer quarantined this node. If the peer is still a live member here, only this side can be shut out -> restart now. - S2 AssociationErrorEvent 'has a UID that has been quarantined': the peer still runs the incarnation this node removed. A healed partition yields only S2, on both sides. Wait ShutOutGrace (60s) for a frozen peer to restart itself, then tiebreak. Tiebreak: the higher address (Akka Member.AddressOrdering) restarts, the lower stays and restarts only if still split one grace later. Removed peers are probed (Identify, 5s -> 60s back-off) since nothing else contacts them after mutual removal. Restart = Cluster.Down(self) -> existing self-down path. The Host now exits 75 after an unplanned ActorSystem termination (and sets it on the Windows service before it reports stopped): SCM recovery with failureflag 1 only restarts a service that stops with a non-zero code, and the watchdog used to exit 0. Shipped default strategy stays auto-down. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
@@ -144,6 +144,61 @@ public class ClusterOptions
|
||||
/// <c>docs/plans/2026-11-09-tls-production-profile-design.md</c>.
|
||||
/// </summary>
|
||||
public ClusterRemotingTlsOptions RemotingTls { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Settings that apply only when <see cref="SplitBrainResolverStrategy"/> is
|
||||
/// <c>leader-auto-down</c> (<c>ScadaBridge:Cluster:LeaderAutoDown</c>, ScadaBridge#132).
|
||||
/// Inert under every other strategy: <c>AkkaHostedService.BuildHocon</c> emits none of it.
|
||||
/// </summary>
|
||||
public LeaderAutoDownOptions LeaderAutoDown { get; set; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <c>leader-auto-down</c>-only settings (ScadaBridge#132): what a node does when it learns that
|
||||
/// its pair peer has <b>shut it out</b> — removed and quarantined it, so it can never talk to that
|
||||
/// peer again until it restarts.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Why it exists.</b> A node that was frozen (VM pause, GC stall, <c>docker pause</c>) past the
|
||||
/// failure-detection window plus <see cref="ClusterOptions.StableAfter"/> is downed and removed by
|
||||
/// its peer. When it resumes, every association is refused with "the remote system has quarantined
|
||||
/// this system" — Akka.Remote publishes <c>ThisActorSystemQuarantinedEvent</c>, but Akka.Cluster
|
||||
/// 1.5.62 never acts on it, so the frozen node downs the peer in its own one-node view and becomes
|
||||
/// a second, permanent active node. The same thing happens to <b>both</b> nodes after a real
|
||||
/// network partition heals.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b>What it does</b> (with <see cref="RestartWhenShutOut"/> on): a node that is shut out by its
|
||||
/// peer while it still counts that peer as a member restarts itself (it is the stale side). When it
|
||||
/// has already removed the peer too — both sides shut each other out — a deterministic tiebreak
|
||||
/// both nodes compute identically picks ONE side: the node with the <b>higher</b> address
|
||||
/// (host, then port; Akka's own member address ordering) restarts, the lower stays. The lower node
|
||||
/// restarts too only if it is still being shut out after <see cref="ShutOutGrace"/>. "Restart" is
|
||||
/// the existing self-down path: <c>Cluster.Down(self)</c>, the <c>ActorSystem</c> terminates, the
|
||||
/// Host exits non-zero and the service supervisor restarts it as a fresh incarnation that rejoins
|
||||
/// as standby. Implemented by <c>ShutOutRestart</c> in the Host.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class LeaderAutoDownOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether a node shut out by its pair peer restarts itself (see the class remarks). Default
|
||||
/// <see langword="true"/> — on whenever <c>leader-auto-down</c> is selected. Set
|
||||
/// <see langword="false"/> to get the old behaviour back: a frozen node or a healed partition
|
||||
/// leaves two active nodes until an operator restarts one.
|
||||
/// </summary>
|
||||
public bool RestartWhenShutOut { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// How long the tiebreak WINNER (the lower-address node) waits for its peer to restart before
|
||||
/// it re-checks. At the end of the grace it restarts only if the peer is still not a member AND
|
||||
/// it was shut out again in the last few seconds — i.e. the peer never restarted, so this node
|
||||
/// is the stale side after all. Must cover the peer's worst-case shut-down time (its old
|
||||
/// incarnation keeps refusing until its <c>ActorSystem</c> has terminated). Default 60s.
|
||||
/// Validated <c>> 0</c> at boot when the feature is on.
|
||||
/// </summary>
|
||||
public TimeSpan ShutOutGrace { get; set; } = TimeSpan.FromSeconds(60);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -74,6 +74,17 @@ public sealed class ClusterOptionsValidator : OptionsValidatorBase<ClusterOption
|
||||
$"FailureDetectionThreshold ({options.FailureDetectionThreshold}); otherwise nodes are " +
|
||||
"declared unreachable before a heartbeat can arrive.");
|
||||
|
||||
// ScadaBridge#132: the shut-out restart grace is only consulted under leader-auto-down
|
||||
// with the feature on; a zero/negative grace would make the tiebreak winner restart on
|
||||
// the spot, i.e. BOTH nodes of a healed partition restart together.
|
||||
var isLeaderAutoDown = string.Equals(
|
||||
options.SplitBrainResolverStrategy, "leader-auto-down", StringComparison.OrdinalIgnoreCase);
|
||||
var leaderAutoDown = options.LeaderAutoDown ?? new LeaderAutoDownOptions();
|
||||
builder.RequireThat(
|
||||
!isLeaderAutoDown || !leaderAutoDown.RestartWhenShutOut || leaderAutoDown.ShutOutGrace > TimeSpan.Zero,
|
||||
"ClusterOptions.LeaderAutoDown.ShutOutGrace must be a positive duration when "
|
||||
+ "LeaderAutoDown.RestartWhenShutOut is on (ScadaBridge#132).");
|
||||
|
||||
// DownIfAlone is a keep-oldest knob; under (leader-)auto-down each side downs the
|
||||
// unreachable peer regardless, so the flag is inert and any value is fine.
|
||||
var isKeepOldest = string.Equals(
|
||||
|
||||
Reference in New Issue
Block a user