Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential issue with Counter internal slice management #1296

Open
bernata opened this issue Jul 19, 2024 · 0 comments
Open

Potential issue with Counter internal slice management #1296

bernata opened this issue Jul 19, 2024 · 0 comments
Labels

Comments

@bernata
Copy link

bernata commented Jul 19, 2024

What did you do?

I created a PR to demonstrate the problem:
#1295

To summarize, there are 4 counters:

	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.

@bernata bernata added the bug label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant