Repository navigation
fix: the gossip default carries a cluster, and truncation says so - #280
Merged
Merged
Conversation
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
enabled auto-merge (squash)
August 3, 2026 18:33
This was referenced Aug 3, 2026
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 #277.
MaxGossipPacketdefaulted to 1024 bytes. A sealed sync message costs ~200 bytes of envelope plus ~415 bytes per member — measured, not estimated, becausesealwraps 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 asMessagesUnauthenticated— 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" —ReadFromUDPdiscards an oversize datagram's tail and reports only what it copied, so one spare byte makesn > MaxGossipPacketunambiguous evidence. Such a datagram is dropped before it reaches the authenticator, counted asMessagesTruncated, 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 asMessagesOversize. 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 becausehandleSyncMessagemerges 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, sosendMessagerefuses it loudly rather than a member being silently dropped.A fourth defect found along the way
NewClusterManager's nil-config literal restated sixteen fields thatapplyConfigDefaultssets to the same values two lines later — including a secondMaxGossipPacket: 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=distributedsuite no longer overridesMaxGossipPacketanywhere — including the65507workaroundTestMultiNodeClustercarried. 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
defaultMaxGossipPacketback to 1024TestNewClusterManager_DefaultMaxGossipPacketHoldsAThreeNodeSync— "a three-member sync took 2 datagrams at the 1024-byte default, want 1"if falseTestReceiveMessages_CountsATruncatedDatagramAsTruncated—MessagesTruncated = 0, want 1andMessagesUnauthenticated = 1, want 0, reproducing #277's exact misdiagnosisif falseTestSendMessage_RefusesAnOversizeDatagramTestSendSyncMessage_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
GossipStatsbut not to the field-by-field copy inGetStats, 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 .— cleango test -count=1 -race -covermode=atomic ./...— exit 0./scripts/coverage-gate.sh— 35 packages at or above floorgolangci-lint --new-from-merge-base=origin/main— 0 issuesgosec ./internal/distributed/— 2 findings, both the pre-existingG404s atconsensus.go:930,933go test -count=1 -race -tags=distributed ./tests/— ok 18.186s, 0 racesgo test ./internal/config/(doc/changelog gates) — ok