thrasher-corp / gocryptotrader

A cryptocurrency trading bot and framework supporting multiple exchanges written in Golang.
MIT License
2.99k stars 802 forks source link

request: fix intermittent race when verbose and reading the body in different routines #1507

Closed shazbert closed 6 months ago

shazbert commented 6 months ago

PR Description

Noted as issue by @cranktakular THANKS MATE.

Fixes # (issue)

WARNING: DATA RACE
Write at 0x00c000624438 by goroutine 29:
  bytes.(*Buffer).Read()
      /Go/src/bytes/buffer.go:329 +0x1c4
  io.(*nopCloserWriterTo).Read()
      <autogenerated>:1 +0x6c
  net/http.(*readTrackingBody).Read()
      /Go/src/net/http/transport.go:657 +0x76
  net/http.(*http2clientStream).writeRequestBody()
      /Go/src/net/http/h2_bundle.go:8760 +0x5d9
  net/http.(*http2clientStream).writeRequest()
      /Go/src/net/http/h2_bundle.go:8467 +0xf32
  net/http.(*http2clientStream).doRequest()
      /Go/src/net/http/h2_bundle.go:8353 +0x33
  net/http.(*http2ClientConn).RoundTrip.gowrap1()
     /Go/src/net/http/h2_bundle.go:8259 +0x44

Previous read at 0x00c000624438 by goroutine 7:
  bytes.(*Buffer).String()
      /Go/src/bytes/buffer.go:71 +0x3a
  fmt.(*pp).handleMethods()
      /Go/src/fmt/print.go:673 +0x6ea
  fmt.(*pp).printArg()
     /Go/src/fmt/print.go:756 +0xb4b
  fmt.(*pp).doPrintf()
     /Go/src/fmt/print.go:1075 +0x592
  fmt.Sprintf()
      /Go/src/fmt/print.go:239 +0x5c
  github.com/thrasher-corp/gocryptotrader/log.Debugf.(*fields).stagef.func1()
     /gocryptotrader/log/loggers.go:274 +0x64
  github.com/thrasher-corp/gocryptotrader/log.loggerWorker()
      /gocryptotrader/log/logger_multiwriter.go:38 +0x155

Type of change

Please delete options that are not relevant and add an x in [] as item is complete.

How has this been tested

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and also consider improving test coverage whilst working on a certain feature or package.

Checklist