-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime/race: potential false positive when synchronizing with unix.Flock() #50139
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
Comments
That sounds about right. I think this would be hard to fix, though. How would you know that two |
|
I don't think Go memory model specifies If you are using If you need to support arbitrary file paths, you could pair that with, say, a |
Thanks everyone for the extremely helpful context. The race condition makes sense—I'd never considered that writes may not occur immediately. Hopefully the details in this issue will be useful for others in future. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
unix.Open("/path/to/file",...)
unix.Flock(fd, unix.LOCK_EX)
Entering critical section
. It then mutates a variable, printsExited critical section
and unlocks (by closing viaunix.Close(fd)
)Full test-case here: https://go.dev/play/p/5CY5B1q9WUf
Note: doesn't run in go.dev/play due to needing the race flag. Repros for me in darwin/arm64 and linux/arm64
Oddities:
unix.Close(fd)
(i.e. after the critical section has been left), and a data race is then detected once it reaches line 33 (testVar++
).What did you expect to see?
What did you see instead?
Is it possible that the synchronization that happens via Flock() is invisible to the race detector, and this is a false positive? I found a potentially related discussion here: #5363 (comment)
The text was updated successfully, but these errors were encountered: