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

Data race while using http.Client concurrently #31373

Closed
pmalekn opened this issue Apr 9, 2019 · 3 comments
Closed

Data race while using http.Client concurrently #31373

pmalekn opened this issue Apr 9, 2019 · 3 comments

Comments

@pmalekn
Copy link

pmalekn commented Apr 9, 2019

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

$ go version
go version go1.12.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/pmalek/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/pmalek/.gvm/pkgsets/go1.12.2/global"
GOPROXY=""
GORACE=""
GOROOT="/Users/pmalek/.gvm/gos/go1.12.2"
GOTMPDIR=""
GOTOOLDIR="/Users/pmalek/.gvm/gos/go1.12.2/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/pmalek/code/project/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zy/lzyp__pd7vx6762s5jcgkkl80000gn/T/go-build893261005=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Use http.Client concurrently

// c.client initialized like so:
// &http.Client{}
var buf bytes.Buffer
// write JSON to buff....
request, err := http.NewRequest("POST", url, &buf)
if err != nil {
	return nil, err
}
request.SetBasicAuth(c.D, c.SessionKey)
request.Header.Add("Content-type", "application/x-ldjson")
rsp, err := c.client.Do(request)

What did you expect to see?

No data race

What did you see instead?

==================
WARNING: DATA RACE
Read at 0x00c001112840 by goroutine 180:
  github.com/org/repo/project/someclient.(*SomeClient).SendStuff()
      /Users/pmalek/.gvm/gos/go1.12.2/src/bytes/buffer.go:68 +0xa63
  github.com/org/repo/otherproject.(*replay).sendSomething.func1()
      /Users/pmalek/code/repo/project/directory/client.go:81 +0x1a52

Previous write at 0x00c001112840 by goroutine 138:
  bytes.(*Buffer).Read()
      /Users/pmalek/.gvm/gos/go1.12.2/src/bytes/buffer.go:101 +0xb5
  io/ioutil.(*nopCloser).Read()
      <autogenerated>:1 +0x87
  net/http.(*http2clientStream).writeRequestBody()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/h2_bundle.go:7664 +0x64d
  net/http.(*http2Transport).getBodyWriterState.func1()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/h2_bundle.go:8878 +0x13d

Goroutine 180 (running) created at:
  github.com/org/repo/otherproject.(*replay).sendSomething()
      /Users/pmalek/code/repo/otherproject/replay.go:187 +0x6a5

Goroutine 138 (running) created at:
  net/http.http2bodyWriterState.scheduleBodyWrite()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/h2_bundle.go:8925 +0x12f
  net/http.(*http2ClientConn).roundTrip()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/h2_bundle.go:7465 +0x90f
  net/http.(*http2Transport).RoundTripOpt()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/h2_bundle.go:6867 +0x23d
  net/http.http2noDialH2RoundTripper.RoundTrip()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/h2_bundle.go:6829 +0x4c
  net/http.(*Transport).roundTrip()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/transport.go:430 +0x14d9
  net/http.(*Transport).RoundTrip()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/roundtrip.go:17 +0x42
  net/http.send()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/client.go:250 +0x6a9
  net/http.(*Client).send()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/client.go:174 +0x1cb
  net/http.(*Client).do()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/client.go:641 +0x4ef
  github.com/org/repo/project/someclient.(*SomeClient).SendStuff()
      /Users/pmalek/.gvm/gos/go1.12.2/src/net/http/client.go:509 +0x4b7
  github.com/org/repo/otherproject.(*replay).sendSomething.func1()
      /Users/pmalek/code/repo/project/directory/client.go:81 +0x1a52
==================
@pmalekn
Copy link
Author

pmalekn commented Apr 9, 2019

It seems that this is connected to (or even a duplicate of) #31192

@bcmills
Copy link
Contributor

bcmills commented Apr 9, 2019

Looking at the stack trace, that seems to be the case.

@bcmills
Copy link
Contributor

bcmills commented Apr 9, 2019

Duplicate of #31192

@bcmills bcmills closed this as completed Apr 9, 2019
@bcmills bcmills marked this as a duplicate of #31192 Apr 9, 2019
@golang golang locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants