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
net/http: race detector not working #52275
Comments
I'm not sure what guarantees the race detector makes about what it's definitely able to detect. Maybe not reporting a race when the curls were done sequentially is a feature, in that there was not actually a race (but could be if the requests arrived at the same time). Or maybe detecting such "potential races" could be a feature request. It seems the following program also doesn't report a race (which likely doesn't happen if you wait enough seconds to be sure the first goroutine completed before providing stdin): package main
import "fmt"
func main() {
counter := 0
go func() {
counter++
fmt.Println(counter)
}()
fmt.Scanln(new(string))
go func() {
counter++
fmt.Println(counter)
}()
// Output (with -race):
// 1
// a
// 2
} CC @ianlancetaylor, @neild. |
The race detector does make an effort to detect potential races. Usually when the race detector fails to report a race it is because there is an unexpected synchroniation/serialization in a library. The later example above will indeed report a race if run as |
CC @dvyukov |
All real races should be eventually detectable. In this case you play role of synchronization since you run curl sequentially ;) As Ian pointed, the false negative happens due to induced io synchronization:
Removing that will lead to false positives and we prefer to err on side of false negatives. It may be possible to restructure http package to run the handler in unsynchronized goroutines. But not sure if it will work b/c the goroutine will still need to accept/read/receive before the handler and send after the handler. |
Thanks, closing as there is nothing we can reasonably do here. |
thanks for clarification |
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?
and run it with
go run -race main.go
, thencurl
it twiceWhat did you expect to see?
race detector detects the race condition
What did you see instead?
race detector doesn't detect the race condition
I believe the go race detector will catch it even though I run
curl
sequentially because in the following code, the race detected do detect it correctlyThe text was updated successfully, but these errors were encountered: