Repository navigation
otelslog: fix shared kvBuffer append corrupting log attributes - #9229
Merged
Merged
Conversation
somaz94
force-pushed
the
9046
branch
2 times, most recently
from
July 14, 2026 07:39
e599fe0 to
4cbc95b
Compare
somaz94
marked this pull request as ready for review
July 21, 2026 07:19
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9229 +/- ##
=======================================
+ Coverage 83.8% 84.0% +0.1%
=======================================
Files 198 198
Lines 16328 16328
=======================================
+ Hits 13695 13717 +22
+ Misses 2157 2135 -22
Partials 476 476
🚀 New features to boost your workflow:
|
MrAlias
approved these changes
Jul 24, 2026
dashpole
approved these changes
Jul 24, 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.
kvBuffer.KeyValuesreturnedappend(b.data, kvs...). Whencap(b.data) > len(b.data)this writeskvsintob.data's spare capacity and returns a slice aliasing that backing array. The buffer is shared across concurrentHandlecalls (a Handler's group attributes,bridges/otelslog/handler.go:382), so two records append into the same backing array at the same time, which both races and corrupts each other's log attributes.The fix clips
b.datato its length so the append allocates a new backing array instead of writing into the shared spare capacity. This mirrors the existingslices.Cloneuse inClone().Validation (local, Go 1.26):
go test -race ./...passes inbridges/otelslog.TestKVBufferKeyValuesDoesNotAliasBackingArray(deterministic) fails, andTestKVBufferKeyValuesConcurrentreports a DATA RACE under-race.go vet,gofmt, andgolangci-lintv2 are all clean.Allocation note: the previously-buggy case where
kvsfit inb.data's spare capacity now allocates a new backing array (needed for correctness); the empty-kvspath stays zero-alloc viaslices.Clip.related: #9046