Repository navigation
fix: let a node contradict a false report of its own death (#272) - #273
Merged
Merged
Conversation
Incarnation numbers were set to 1 at construction and nothing ever incremented them. Every comparison that depends on one is strictly-greater, so all of them were false for every message after the one that discovered a node. The cost is not a degraded metric, it is a lost node. checkSuspicions promotes suspect to dead and nothing demoted it; the only path back to alive was handleJoinMessage, reachable solely by a process restart. So a few dropped datagrams — the normal condition of UDP — removed a healthy node from routing permanently. Proven before fixing: a node discovered at state 0 was still at state 2 after an alive message from it arrived. A node now refutes an accusation about itself rather than recording it. Refusing to record it matters as much as the refutation: performGossip and broadcastMessage both skip nodes that are not alive, so a node that accepted a suspicion about itself would stop gossiping and make the report true. The new incarnation is one past the higher of ours and theirs, or a peer holding a stale higher number would keep rejecting the refutation; an accusation naming an incarnation already superseded is ignored, which is what makes the exchange converge instead of ring. The frozen statistics are the same guard from the other side. An incarnation orders claims about liveness and says nothing about the freshness of the figures riding along with the claim, and a healthy node never raises its incarnation because it has nothing to refute — so gating the payload on a strict increase pinned every peer's stats to the moment it was discovered. An equal incarnation now refreshes the payload without touching the state machine, and only for a node already believed alive, so it cannot become a second path back from dead. performGossip also stamps its own LastSeen before announcing itself. It was broadcasting the timestamp set at construction, and since UpdateNodeInfo copies that field and performHealthChecks compares it against three heartbeat intervals, every alive message a node sent was evidence it had not been heard from — inert only while the guard discarded the payload, and a flap the moment it stopped. The acceptance test #132 proposes for the stats half (wait two heartbeats, assert MemoryUsage > 0) passes on this bug: the first message is applied and the value stays non-zero forever after. These tests assert that a changed value arrives on a second message and that dead becomes alive, because a single-transition assertion cannot tell a live feed from a permanently stale one. Nine mutations checked, each failing a test that names the consequence. Closes #272
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #272.
The defect
GossipNode.Incarnationwas set to1in the constructor and nothing ever incremented it — the only two other writes copy a value received from a peer. Every comparison that depends on an incarnation is strictly-greater, so all of them were false for every message after the one that discovered a node.Two consequences, both proven by execution before fixing:
checkSuspicionspromotes suspect → dead and nothing demoted it. The only path back to alive washandleJoinMessage, reachable solely by a process restart. A few dropped datagrams — the normal condition of UDP — removed a healthy node from routing permanently. Probe:discovered: state=0/after alive from a recovered node: state=2.after first alive: CPUUsage=0.1/after second alive: CPUUsage=0.1 (sender said 0.9).The fix
Refutation. A node answers a suspect or dead report about itself by publishing a higher incarnation, which supersedes the accusation everywhere it has spread. Refusing to record it matters as much:
performGossipandbroadcastMessageboth skip non-alive nodes, so a node that accepted a suspicion about itself would stop gossiping and make the report true. Sync messages are answered too — a full sync is often where a node learns it was written off during a partition.Two details that are load-bearing rather than incidental:
self+1produces a number that peer's own guard rejects, and the disagreement never resolves.Resurrection. An alive message at a higher incarnation restores a dead or suspect node, in the cluster manager as well as the memberlist — the cluster manager is what
SelectNodesreads, so a node restored only in gossip is still absent from routing.Stats refresh. An incarnation orders claims about liveness; it says nothing about the freshness of the figures riding along with the claim, and a healthy node never raises its incarnation because it has nothing to refute. An equal incarnation now refreshes the payload without touching the state machine — only for a node already believed alive, so the refresh cannot become a second, unguarded path back from dead.
One adjacent defect this activated.
performGossipbroadcast theLastSeenset at construction and never refreshed it.UpdateNodeInfocopies that field andperformHealthCheckscompares it against three heartbeat intervals, so every alive message a node sent was evidence it had not been heard from. Inert only while the incarnation guard discarded the payload — a flap the moment it stopped. Now stamped, in the same critical section that reads the incarnation so a refutation cannot land between the two and publish the old number with the new stats.Why the tests are shaped this way
#132's stated acceptance criterion for the stats half — "wait 2× heartbeat, assert `MemoryUsage > 0`" — passes on this bug. The first message is applied, so the value is non-zero forever after. A green test over a permanently stale metric is worse than no test: it certifies the thing it cannot see.
So the assertions are that a changed value arrives on a second message, and that dead becomes alive. Nine mutations checked, each reverting one part of the fix:
RefutesSuspicionAboutItself,RefutesDeathReportAboutItself,RefutationOutranksTheAccusation,HandleSyncMessage_SkipsSelfGossipedStatsAreNotFrozenAtTheFirstValueAliveMessageDoesNotResurrectAtTheSameIncarnationAliveMessageResurrectsADeadNode,HandleAliveMessage_UpdatesExistingRefutesSuspicionAboutItself,RefutationOutranksTheAccusationRefutesDeathReportAboutItselfHandleSyncMessage_SkipsSelfStaleAccusationAboutItselfIsIgnoredLastSeennot stampedPerformGossipStampsItsOwnLastSeenOne existing test was retargeted rather than deleted:
HandleSyncMessage_SkipsSelfasserted the self incarnation was unchanged after a sync claiming we are dead at 999, which the fix deliberately changes. Its intent — don't take a peer's word for our own state — still holds, and it now asserts the incarnation ends up above the accusation, since a refutation the accuser's own guard would reject is not a refutation.Gates
This is the prerequisite for #132 — without it nothing in that issue has an observable effect after startup.