-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
sync: Map CompareAndSwap is not atomic with respect to other map operations in Go 1.24 #70970
Comments
I'm going to spend a little time staring at your code to try to figure out what I think ought to be happening, but it might not hurt if comments in the example or a later commentary explained what you thought was supposed to be going on. It can be easier to check your assumptions, than to run this GC-interacting piece of code in my error-prone head. |
You're absolutely right. I don't have time right now, but I'll get back to it later today. Sorry for the missing comments, I was too deep in the weeds to notice. |
I think this is the doc comment you would want to prepend to
And the larger expectation is that because the returned value from the first call (assigned to
If this is your bug, it is darn subtle, because I don't see it. I will keep looking. I don't see where it needs a keepalive, either. And thank you, I am betting "our bug" at this point, and this close to release it needs attention. |
This is a bug in the map implementation, I think. I think I know how to fix the problem. I should have a CL out shortly. Worst case we switch the GOEXPERIMENT default back to the old map implementation, but I don't think it'll come to that. |
I'm fairly certain the problem was introduced in CL 606462 and that rolling back that change will resolve this issue. That being said, I will take a little bit of time to try and salvage that optimization with high confidence that we don't introduce any newer, subtler bugs. |
Change https://go.dev/cl/638559 mentions this issue: |
CL 638559 is a fix that works. It still needs a test and a little bit of cleanup, but I feel OK about it. It's a bit late in the release cycle. Here are our options:
|
I guess I don't need to update the snippet above with better comments now, I'll keep in mind for next time though. Great job in pin-pointing that bug so quickly, btw. |
@mknyszek How noticeable is the performance regression? |
I'll measure it. IIRC, there was one microbenchmark in the existing |
Change https://go.dev/cl/638615 mentions this issue: |
Go version
go version devel go1.24-eef35e3bd9 Mon Dec 23 07:08:40 2024 -0800 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
I am experimenting with weak maps and ran into a problem that I can't explain. I am either missing something and there's a bug somewhere in my implementation or there's a bug in Go.
I reduced the problem to
What did you see happen?
Unfortunately, this is a bit flaky and it doesn't always reproduce. I sometimes have to run the program multiple times. When it reproduces it prints something like this:
I can also reproduce it on the Go playground: https://go.dev/play/p/HBJ2IU2IGdF?v=gotip
What did you expect to see?
I expect to always observe that same pointer being returned by get for the same key.
The text was updated successfully, but these errors were encountered: