Repository navigation
exp/api/remote: reset pooled buffer before generic marshal - #2139
Merged
kakkoyun merged 1 commit intoOct 3, 2026
Merged
Conversation
Signed-off-by: lowgame <128625014+lowgame@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The targeted fix correctly addresses the append semantics and includes appropriate regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes stale pooled bytes corrupting payloads in the experimental remote-write client’s generic protobuf path.
Changes:
- Reset the pooled buffer before
MarshalAppend. - Add a deterministic regression test covering generic protobuf serialization.
| File | Description |
|---|---|
exp/api/remote/remote_api.go |
Resets the buffer while retaining capacity. |
exp/api/remote/remote_api_test.go |
Verifies stale bytes are excluded from requests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
kakkoyun
enabled auto-merge (squash)
October 3, 2026 10:50
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.
@vesari, this fixes corruption in the experimental remote-write client's generic protobuf path.
Reproduction
A regression test seeds the API's buffer pool with a non-empty slice, sends a protobuf message that uses the generic
proto.Messagebranch, decompresses the HTTP request body, and compares it withproto.Marshaloutput. Before the production change it failed deterministically:The leading bytes are the stale pooled contents.
Root cause
proto.MarshalOptions.MarshalAppendappends to the destination's current length. Buffers returned by the API pool can retain a non-zero length after a previous write, but the generic protobuf branch passed that slice directly toMarshalAppend. The optimized vtprotobuf and gogo branches already resize their buffers before writing.Solution
Reset the pooled slice to length zero before the generic marshal while retaining its capacity. The regression test exercises this branch with
timestamppb.Timestamp, which implementsproto.Messagebut not the optimized marshal interfaces.Validation
From
exp/:go test ./api/remote -run '^TestRemoteAPI_Write_GenericProtoResetsPooledBuffer$' -count=1— passgo test -race ./api/remote -run '^TestRemoteAPI_Write_GenericProtoResetsPooledBuffer$' -count=10— passgo test ./api/remote/... -count=1— passgo test ./... -count=1— passgo vet ./...— passgolangci-lint run --new-from-rev=HEAD ./api/remote/...— 0 new issuesThe unrestricted lint run reports five pre-existing findings in unchanged lines (one
modernize, onerevive, and threeusestdlibvars).