Skip to content

fix(distributed): a size failure that arrived as a timeout, and a backend swap that raced (#399) - #400

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/399-oversize-response-reporting
Aug 9, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/399-oversize-response-reporting

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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.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 — 38.9% inflation, not base64's 33%. The kernel's MaxRead is 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. ErrMessageOversize is the sentinel, so the one caller that can do better than fail need not match on the error text.

Raising max_gossip_packet is 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

SetBackend assigned cm.coordinator.backend while holding the cluster's mutex, and executeLocally read 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:

  • Oversize branch disabled → TestCoordinator_RemoteGet_ReportsAnOversizeResponseRatherThanTimingOut fails 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.
  • Locked read reverted to a bare field access → -race reports the write/read pair in TestClusterManager_SetBackend_IsSafeWhileAPeerOperationRuns.

go build ./..., gofmt -l, go vet ./..., golangci-lint run clean. go test -race ./... green. go test -race -tags=distributed -count=2 ./internal/distributed/... green.

…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.
@scttfrdmn
scttfrdmn enabled auto-merge (squash) August 9, 2026 02:36
@scttfrdmn
scttfrdmn merged commit 6d0937b into main Aug 9, 2026
35 checks passed
@scttfrdmn
scttfrdmn deleted the fix/399-oversize-response-reporting 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A remote node's operation response cannot carry an object: the sealed datagram exceeds max_gossip_packet above 5802 bytes

1 participant