Skip to content

fix: the gossip default carries a cluster, and truncation says so - #280

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/gossip-packet-size
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/gossip-packet-size

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #277.

MaxGossipPacket defaulted to 1024 bytes. A sealed sync message costs ~200 bytes of envelope plus ~415 bytes per member — measured, not estimated, because seal wraps the payload in JSON with a hex MAC and base64-encodes the byte field, so the payload:datagram ratio is not a constant one can reason to. 1024 bytes held two members. A third node's sync was truncated by the receive buffer, the truncated JSON failed the authentication envelope parse, and the failure was counted and logged as MessagesUnauthenticated — whose documented meaning is a peer configured with a different cluster secret. So the symptom of a size limit was a message sending the operator to verify a secret that was correct, and membership stalled at two nodes.

Measured sealed sizes (throwaway probe, since deleted): 1 member = 622 B, 3 = 1448, 5 = 2262, 10 = 4333, 25 = 10520, 50 = 20841, 100 = 41476. Alive message = 483 B.

Three separable defects

The default is now 8192, carrying ~19 members in one datagram. Not 65507, the maximum UDP payload: a datagram over the path MTU is fragmented by IP and a single lost fragment loses the whole datagram, so effective loss rate rises with size. 8 KiB does exceed a 1500-byte MTU and will fragment — a deliberate trade, since six fragments for a sync that runs once per join is worth more than chunking every small cluster's membership across several round trips. Per-round alive messages never fragment.

Truncation is detected and reported as truncation. The receive buffer is MaxGossipPacket+1, because a buffer sized exactly to the limit cannot distinguish "at the limit" from "truncated" — ReadFromUDP discards an oversize datagram's tail and reports only what it copied, so one spare byte makes n > MaxGossipPacket unambiguous evidence. Such a datagram is dropped before it reaches the authenticator, counted as MessagesTruncated, and logged with the limit and the instruction to set the same value on every node. An oversize send is refused after sealing (the last point the size is knowable, the first it is final) and counted as MessagesOversize. The two directions are counted separately because the operator action differs: an oversize send is this node's memberlist outgrowing its own limit; a truncated receive is a peer whose limit is larger than ours.

Sync messages are chunked rather than unbounded. Each chunk is a complete SyncMessage — sound because handleSyncMessage merges per node rather than replacing wholesale, so a receiver applying two chunks reaches the same state as one applying their union. Boundaries are computed over a sorted key order so they are a function of the membership rather than of Go's map iteration order, and each candidate chunk is sealed to measure it, so the budget includes envelope, MAC, and message ID. A single member too large for any datagram is emitted alone and logged, so sendMessage refuses it loudly rather than a member being silently dropped.

A fourth defect found along the way

NewClusterManager's nil-config literal restated sixteen fields that applyConfigDefaults sets to the same values two lines later — including a second MaxGossipPacket: 1024. It is now one field, CacheReplication, the only one it was ever load-bearing for, because it is a bool defaulting to true and a bool's zero value cannot be distinguished from unset. A duplicated default is how a stale copy survives a fix to the default.

Why the tagged suite is the load-bearing verification

The -tags=distributed suite no longer overrides MaxGossipPacket anywhere — including the 65507 workaround TestMultiNodeCluster carried. A test that sets the value cannot notice the default regressing, so removing the override is what makes the suite cover this. It passes unaided: go test -count=1 -race -tags=distributed ./tests/ → ok in 18.186s, 0 races.

Likewise the unit test asserts that a three-member sync fits in one datagram — the property the issue is about — rather than asserting the constant equals 8192, which would only prove a constant equals itself. It uses realistic hostnames, because a hostname's length is part of what decides whether this fits.

Mutation verification

mutation caught by
defaultMaxGossipPacket back to 1024 TestNewClusterManager_DefaultMaxGossipPacketHoldsAThreeNodeSync — "a three-member sync took 2 datagrams at the 1024-byte default, want 1"
truncation check → if false TestReceiveMessages_CountsATruncatedDatagramAsTruncated — MessagesTruncated = 0, want 1 and MessagesUnauthenticated = 1, want 0, reproducing #277's exact misdiagnosis
oversize refusal → if false TestSendMessage_RefusesAnOversizeDatagram
chunking disabled TestSendSyncMessage_ChunksAMemberlistThatDoesNotFit — "a 21-member sync produced 1 chunk(s) at a 2048-byte limit, want several"

The chunking test asserts every chunk seals under the limit, each unmarshals as a complete SyncMessage, and the union carries exactly the whole memberlist with nothing lost or duplicated — deliberately without pinning the chunk count. The truncation test writes valid oversize JSON so it distinguishes the two causes rather than passing for the wrong reason.

One omission caught during review and worth noting: the two new counters were initially added to GossipStats but not to the field-by-field copy in GetStats, so the new tests would have silently read zeros. That is the exact trap a hand-maintained struct copy invites.

Gates

go build ./... · go vet ./... · gofmt -l . — clean
go test -count=1 -race -covermode=atomic ./... — exit 0
./scripts/coverage-gate.sh — 35 packages at or above floor
golangci-lint --new-from-merge-base=origin/main — 0 issues
gosec ./internal/distributed/ — 2 findings, both the pre-existing G404s at consensus.go:930,933
go test -count=1 -race -tags=distributed ./tests/ — ok 18.186s, 0 races
go test ./internal/config/ (doc/changelog gates) — ok

MaxGossipPacket defaulted to 1024 bytes. A sealed sync message costs ~200
bytes of envelope plus ~415 bytes per member — measured, because seal wraps
the payload in JSON with a hex MAC and base64-encodes the byte field, so the
payload:datagram ratio is not a constant to reason to. 1024 held *two*
members. A third node's sync was truncated by the receive buffer, the
truncated JSON failed the authentication envelope parse, and the failure was
counted as MessagesUnauthenticated — documented as "a peer with a different
cluster secret." So a size limit presented as a wrong secret and sent the
operator to verify one that was correct, while membership stalled at two.

Three separable defects, each fixed on its own terms rather than by raising
one number.

The default is 8192, holding ~19 members. Not 65507: a datagram over the path
MTU fragments and one lost fragment loses all of it, so effective loss rises
with size. 8 KiB does fragment on a 1500-byte MTU — a deliberate trade, since
six fragments for a once-per-join sync beats chunking every small cluster's
membership across round trips. Alive messages are ~483 bytes and never
fragment.

Truncation is detected and reported as truncation. The receive buffer is
MaxGossipPacket+1, because a buffer sized exactly to the limit cannot
distinguish "at the limit" from "truncated" — ReadFromUDP discards the tail
and reports only what it copied, so one spare byte makes n > MaxGossipPacket
unambiguous. Such a datagram is dropped before the authenticator, counted as
MessagesTruncated, and logged with the limit. An oversize send is refused
after sealing and counted as MessagesOversize. The directions are counted
separately because the operator action differs: an oversize send is this
node's memberlist outgrowing its own limit, a truncated receive is a peer
whose limit is larger than ours.

Sync messages are chunked. Each chunk is a complete SyncMessage, which is
sound because handleSyncMessage merges per node rather than replacing, so a
receiver applying two chunks reaches the same state as one applying their
union. Boundaries are computed over sorted keys so they are a function of the
membership, not of map iteration order, and each candidate is sealed to
measure it so the budget includes envelope, MAC, and message ID.

A fourth defect found along the way: NewClusterManager's nil-config literal
restated sixteen fields applyConfigDefaults sets two lines later, including a
second MaxGossipPacket: 1024. It is now one field — CacheReplication, the only
one it was load-bearing for, since a bool defaulting to true cannot express
"unset." A duplicated default is how a stale copy survives a fix.

The -tags=distributed suite no longer overrides MaxGossipPacket anywhere,
which is what makes it cover this: a test that sets the value cannot notice
the default regressing. That suite passes unaided, and the unit test asserts a
three-member sync fits one datagram — the property at issue — rather than that
a constant equals itself.

All four new tests are mutation-verified. Reverting the truncation check makes
the test report MessagesUnauthenticated = 1, want 0, reproducing the exact
misdiagnosis the issue describes.

Closes #277
@scttfrdmn scttfrdmn added type: bug Something isn't working as expected priority: high Important issue that should be addressed soon area: distributed Distributed coordination and consensus labels Aug 3, 2026
@scttfrdmn
scttfrdmn enabled auto-merge (squash) August 3, 2026 18:33
@scttfrdmn
scttfrdmn merged commit 93628c1 into main Aug 3, 2026
27 checks passed
@scttfrdmn
scttfrdmn deleted the fix/gossip-packet-size branch September 20, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: distributed Distributed coordination and consensus priority: high Important issue that should be addressed soon type: bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gossip: the 1024-byte MaxGossipPacket default truncates sync messages, which then fail authentication

1 participant