go-kit / go-kit/kit

Potential issue with Counter internal slice management

Open
#1,296 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
27.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

### What did you do?

I created a PR to demonstrate the problem:
https://github.com/go-kit/kit/pull/1295

To summarize, there are 4 counters:
```golang
c1 := (&Counter{}).With("a", "1", "b", "2", "c", "3", "d", "4")
c2 := c1.With("e", "5").(*Counter)
c3 := c2.With("f", "6", "g", "7").(*Counter)
c4 := c2.With("h", "8").(*Counter)
```

The counters `c3` and `c4` share the same backing memory for the counter lvs slice. As a result, `c4` will overwrite the contents of `c3` lvs slice. So in the example above, at the end of the execution, c3 lvs internal slice has values: `a 1 b 2 c 3 d 4 e 5 h 8 g 7`

### What did you expect?

The expectation I have is c3 lvs internal slice has values: `a 1 b 2 c 3 d 4 e 5 f 6 g 7`
I assumed it behaved a bit like context.WithValue which I think would have similar behavior in keeping the parent-child contexts free from overwrite.

### What happened instead?

The c3 lvs internal slice has values: `a 1 b 2 c 3 d 4 e 5 h 8 g 7` because `c4` overwrote part of the `c3` slice.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.