mapper: fix phantom updateSentPeers on disconnected nodes

When send() is called on a node with zero active connections
(disconnected but kept for rapid reconnection), it returns nil
(success). handleNodeChange then calls updateSentPeers, recording
peers as delivered when no client received the data.

This corrupts lastSentPeers: future computePeerDiff calculations
produce wrong results because they compare against phantom state.
After reconnection, the node's initial map resets lastSentPeers,
but any changes processed during the disconnect window leave
stale entries that cause asymmetric peer visibility.

Return errNoActiveConnections from send() when there are no
connections. handleNodeChange treats this as a no-op (the change
was generated but not deliverable) and skips updateSentPeers,
keeping lastSentPeers consistent with what clients actually
received.
This commit is contained in:
Kristoffer Dalby
2026-04-08 12:27:04 +00:00
committed by Kristoffer Dalby
parent 9371b4ee28
commit 3587225a88
3 changed files with 22 additions and 4 deletions

View File

@@ -339,8 +339,9 @@ func TestMultiChannelSend_ZeroConnections(t *testing.T) {
err := mc.send(testMapResponse())
require.NoError(t, err,
"sending to node with 0 connections should succeed silently (rapid reconnection scenario)")
require.ErrorIs(t, err, errNoActiveConnections,
"sending to node with 0 connections should return errNoActiveConnections "+
"so callers skip updateSentPeers (prevents phantom peer state)")
}
func TestMultiChannelSend_NilData(t *testing.T) {