net/http: undocumented race condition on simultaneous calls to (*http.Server).Serve #16505

Closed
benburkert opened this Issue Jul 26, 2016 · 4 comments

Projects

None yet

4 participants

@benburkert
Contributor

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?

go version go1.7rc3 darwin/amd64

  1. What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/benburkert"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7rc3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7rc3/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jl/n78jzg3j6nb8nzbn1vvpg9xc0000gn/T/go-build053329638=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
  1. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.

run this with the race detector: https://play.golang.org/p/9WopZBGsFq

  1. What did you expect to see?

I think the documentation should mention that it is not safe to call Serve with multiple listeners. I have seen this pattern repeated many times for the http & https listeners.

  1. What did you see instead?

Data race warning: https://gist.github.com/benburkert/4eb8e7e4acb72984f7568f4e1fdf1847

@nhooyr
Contributor
nhooyr commented Jul 26, 2016 edited

This was introduced by http2.

http.Server.http2ConfigureServer can write to s.TLSConfig at the same time as http.Server.shouldConfigureHTTP2ForServe can read it.

@bradfitz
Member

This was introduced by http2.

No, it was introduced in b5f0aff which was one month ago. Go 1.6 included http2 and doesn't exhibit this race.

@bradfitz bradfitz added this to the Go1.7Maybe milestone Jul 26, 2016
@bradfitz bradfitz self-assigned this Jul 26, 2016
@nhooyr
Contributor
nhooyr commented Jul 26, 2016

Oh, my bad, sorry.

@gopherbot

CL https://golang.org/cl/25280 mentions this issue.

@gopherbot gopherbot pushed a commit that closed this issue Jul 27, 2016
@bradfitz bradfitz net/http: fix data race with concurrent use of Server.Serve
Fixes #16505

Change-Id: I0afabcc8b1be3a5dbee59946b0c44d4c00a28d71
Reviewed-on: https://go-review.googlesource.com/25280
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
c80e0d3
@gopherbot gopherbot closed this in c80e0d3 Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment