Repository navigation
fix(distributed): a size failure that arrived as a timeout, and a backend swap that raced (#399) - #400
Merged
Conversation
…kend swap that raced (#399) A remote operation's response travels the gossip UDP socket, where the sealed datagram is capped by max_gossip_packet. NodeResult.Data is a []byte, so encoding/json base64-encodes it and the envelope and MAC go on top: at the default 8192-byte limit a response carries at most 5802 bytes of object, an inflation of 38.9% rather than base64's 33%. The kernel's MaxRead is 128 KiB, so essentially every read is over the limit. The ceiling is not the defect. The responder logged the refusal at Warn and returned having sent nothing, so the requester waited out its full timeout and reported "operation timed out waiting for remote response" — a size failure, 30 seconds later, on a different host, at a level most deployments do not collect. An operator debugging that examines the network, the peer's health and the timeout value, and the thing that is wrong is not among them. The verdict fits in a datagram even when the bytes do not, so send the failure in place of the data, naming the payload size, the limit and the setting that governs it. ErrMessageOversize is the sentinel, so the one caller that can do better than fail need not match on the text. Raising max_gossip_packet is the obvious move and is worse: past the ~1500-byte path MTU the datagram is IP-fragmented and one lost fragment discards all of it, trading a clean error for loss that scales with size. Object bytes do not belong on this transport — #142 warms from S3 and puts only metadata on the wire. Writing the test surfaced a second defect, in production code. SetBackend assigned cm.coordinator.backend under the *cluster's* mutex while executeLocally read the field under no lock at all, from the gossip receive goroutine — two different locks and an unsynchronized read of an interface value. It stayed latent because every existing test injects its backend before Start, when the reader goroutine does not yet exist; that is an ordering no caller is required to observe, and #139 makes it routinely false. The backend now has accessors that hold the coordinator's own lock, and is read once per operation rather than at each switch arm, so a put and its ETag read cannot land on two different backends. Both fixes were verified by mutation: with the oversize branch disabled the test fails on the timeout text after 5s, and with the locked read restored to a bare field access -race reports the pair.
… did not
misspell on "behaviour" and two modernize/waitgroupgo findings on the
`wg.Add(1); go func(){ defer wg.Done() ... }()` shape, which Go 1.26's
WaitGroup.Go replaces.
Worth recording why they were missed locally: `golangci-lint run
./internal/distributed/...` reported clean on the same binary and the same
config. CI runs `--new-from-merge-base=origin/main`, which is not the same
filter, and it is the one that gates the merge.
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 #399.
The reported defect
A remote operation's response travels the gossip UDP socket, where the sealed datagram is capped by
max_gossip_packet.NodeResult.Datais a[]byte, soencoding/jsonbase64-encodes it and the envelope and MAC go on top: at the default 8192-byte limit a response carries at most 5802 bytes of object — 38.9% inflation, not base64's 33%. The kernel'sMaxReadis 128 KiB, so essentially every read is over the limit.The ceiling is not the defect. How it presented was. The responder logged the refusal at Warn and returned having sent nothing, so the requester waited out its full timeout and reported
operation timed out waiting for remote response— a size failure, 30 seconds later, on a different host, at a level most deployments do not collect. An operator debugging that examines the network, the peer's health and the timeout value, and the thing that is actually wrong is not among them.The verdict fits in a datagram even when the bytes do not, so the failure is now sent in place of the data, naming the payload size, the limit and the setting that governs it.
ErrMessageOversizeis the sentinel, so the one caller that can do better than fail need not match on the error text.Raising
max_gossip_packetis not the fix and was not applied. Past the ~1500-byte path MTU the datagram is IP-fragmented and one lost fragment discards all of it, trading a clean error for intermittent loss that scales with size. Object bytes do not belong on this transport — #142 warms from S3 and puts only metadata on the wire. No stream transport here either; that is its own piece of work.A second defect, found while writing the test
SetBackendassignedcm.coordinator.backendwhile holding the cluster's mutex, andexecuteLocallyread the field under no lock at all — from the gossip receive goroutine, which is where a peer's operation runs. Two different locks and an unsynchronized read of an interface value.It stayed latent because every existing test injects its backend before
Start, when the goroutine that reads the field does not yet exist. That is an ordering no caller is required to observe, and #139 makes it routinely false. The backend now has accessors holding the coordinator's own lock, and is read once per operation rather than at each switch arm — so a put and its ETag read cannot land on two different backends.Verification
Both fixes verified by mutation, not by prediction:
TestCoordinator_RemoteGet_ReportsAnOversizeResponseRatherThanTimingOutfails after 5s on the timeout text (error does not mention "max_gossip_packet"). With the fix it passes in 1.5s with the real reason.-racereports the write/read pair inTestClusterManager_SetBackend_IsSafeWhileAPeerOperationRuns.go build ./...,gofmt -l,go vet ./...,golangci-lint runclean.go test -race ./...green.go test -race -tags=distributed -count=2 ./internal/distributed/...green.