Skip to content

fix: let a node contradict a false report of its own death (#272) - #273

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/incarnation-liveness
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/incarnation-liveness

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #272.

The defect

GossipNode.Incarnation was set to 1 in 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:

  1. A node marked dead could never rejoin. checkSuspicions promotes suspect → dead and nothing demoted it. The only path back to alive was handleJoinMessage, 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.
  2. Every peer's gossiped statistics froze at the first value ever received. Probe: 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: performGossip and broadcastMessage both 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:

  • The new number is one past the higher of ours and theirs, not ours plus one. A peer restored from an old snapshot can hold a higher incarnation for us than we published; refuting with self+1 produces a number that peer's own guard rejects, and the disagreement never resolves.
  • An accusation naming an incarnation we have already superseded is ignored. Without that, two nodes with stale views each refute the other's refutation and the incarnation climbs without bound.

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 SelectNodes reads, 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. performGossip broadcast the LastSeen set at construction and never refreshed it. UpdateNodeInfo copies that field and performHealthChecks compares 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:

mutation caught by
incarnation never advances (the original defect) RefutesSuspicionAboutItself, RefutesDeathReportAboutItself, RefutationOutranksTheAccusation, HandleSyncMessage_SkipsSelf
no same-incarnation stats refresh GossipedStatsAreNotFrozenAtTheFirstValue
same-incarnation refresh ignores state AliveMessageDoesNotResurrectAtTheSameIncarnation
dead nodes not resurrected AliveMessageResurrectsADeadNode, HandleAliveMessage_UpdatesExisting
self-suspect recorded instead of refuted RefutesSuspicionAboutItself, RefutationOutranksTheAccusation
self-death accepted instead of refuted RefutesDeathReportAboutItself
sync refutation removed HandleSyncMessage_SkipsSelf
stale-accusation guard dropped StaleAccusationAboutItselfIsIgnored
LastSeen not stamped PerformGossipStampsItsOwnLastSeen

One existing test was retargeted rather than deleted: HandleSyncMessage_SkipsSelf asserted 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

  • `go build ./...` · `go vet ./...` · `gofmt -l .` → clean
  • Full `-race` suite: exit 0
  • Coverage gate: 35 packages at or above floor; `internal/distributed` 69.5% → 71.3%
  • `golangci-lint --new-from-merge-base=origin/main`: 0 issues
  • gosec: only the two pre-existing `G404` findings at `consensus.go:856,859`

This is the prerequisite for #132 — without it nothing in that issue has an observable effect after startup.

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
@scttfrdmn
scttfrdmn enabled auto-merge (squash) August 3, 2026 16:57
@scttfrdmn
scttfrdmn merged commit 2ecdf15 into main Aug 3, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

distributed: incarnation numbers never increment, so a node marked dead stays dead and gossiped stats freeze at their first value

1 participant