Skip to content

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

Closed

Description

@scttfrdmn

Found while verifying #132's premises. It is the prerequisite for that issue, but it is a liveness
defect in its own right and larger than the stats field it was found through, so it is filed
separately.

The defect

GossipNode.Incarnation is set to 1 when a node is created (gossip.go:206) and never
incremented anywhere in the package
. The only two writes to the field both copy a value received
from a peer:

$ grep -n '\.Incarnation = ' internal/distributed/*.go | grep -v _test
internal/distributed/gossip.go:523:			gossipNode.Incarnation = aliveMsg.Incarnation
internal/distributed/gossip.go:672:			localNode.Incarnation = remoteNode.Incarnation

and getCurrentIncarnation (gossip.go:967-975) returns the stored value, so every alive message a
node ever sends carries incarnation 1 for its whole lifetime.

handleAliveMessage applies an update only when the received incarnation is strictly greater than
the stored one (gossip.go:522):

if aliveMsg.Incarnation > gossipNode.Incarnation {

Since the value never changes, that condition is false for every alive message after the one that
discovered the node. In SWIM, incarnation is the mechanism by which a node refutes a suspicion about
itself — it increments and re-announces. Here there is nothing to increment, so there is no refutation.

Two consequences, both proven by execution

Probes drove handleIncomingMessage directly with sealed alive messages, so neither result depends on
timing or on reading the source correctly.

1. A node marked dead can never return.

discovered: state=StateAlive
after alive from a recovered node: state=StateDead
--- FAIL: a recovered node stayed StateDead; an alive message did not resurrect it

checkSuspicions promotes suspect → dead on timeout (gossip.go:820-824). Nothing demotes dead →
alive: handleAliveMessage's update is gated on the incarnation that cannot rise, and its
else branch only runs for a node not in the memberlist — a dead node is still in it. So any node
that is briefly unreachable — a network blip, a long GC pause, a slow flush — is removed from routing
permanently, for the lifetime of the observing process.

The only escape is handleJoinMessage (gossip.go:456-462), which overwrites the entry
unconditionally. That means recovery requires the node to restart and re-run JoinNode against a
seed. A node that never stopped, and is answering, does not recover. In a three-node cluster, two
independent blips leave every node routing to itself.

2. Gossiped node stats freeze at the first value observed.

after first  alive: CPUUsage=0.1
after second alive: CPUUsage=0.1 (sender said 0.9)
--- FAIL: stats did not update on the second alive message: got 0.1, want 0.9

performGossip sends the full NodeInfo in every alive message and UpdateNodeInfo copies all six
stats fields, so the transport for #132 already exists and works — but only once per node. This is why
#132 cannot be implemented as written: its acceptance test ("wait 2× heartbeat, assert
MemoryUsage > 0") passes on this bug, because the first message is applied. It would be green over
a metric that is frozen forever.

Why this is not caught today

Every existing test drives one state transition per node. The bug needs two: discover, then update.
It also cannot be reached through the suspect path in a unit test, because checkSuspicions requires a
wall-clock timeout to elapse.

Fix

Increment the local node's incarnation when it has something new to assert — each gossip round, or on
each stats refresh — so that alive messages carry a rising value and the > guard means what it was
written to mean. Then allow a dead node to be resurrected by an alive message at a higher incarnation,
which is what the guard exists to make safe: without it, a stale in-flight alive message could undo a
correct dead marking.

Note the incarnation must not be persisted to be useful here (a restarting node resets to 1, and the
join path already covers restart). What matters is that it rises within a process's lifetime.

Tests must assert a changed value propagates and that a dead node returns to alive, since asserting
a first value or a single transition passes on the current code.

Activity

  1. added
    type: bug
    priority: high
    area: distributed
    on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: distributedpriority: hightype: bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions