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

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

Merged
merged 4 commits into from
Mar 25, 2024

Conversation

shazbert
Copy link
Collaborator

@shazbert shazbert commented Mar 20, 2024

PR Description

Noted as issue by @cranktakular THANKS MATE.

Fixes # (issue)

  • race when doRequest is called and the io.Reader as request.Body is sent to the log package which is deferred to another routine.
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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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.

  • go test ./... -race
  • golangci-lint run
  • Test X

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation and regenerated documentation via the documentation tool
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally and on Github Actions with my changes
  • Any dependent changes have been merged and published in downstream modules

@shazbert shazbert added bug review me This pull request is ready for review labels Mar 20, 2024
@shazbert shazbert requested a review from a team March 20, 2024 01:23
@shazbert shazbert self-assigned this Mar 20, 2024
Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏎️💨💨💨💨💨💨💨💨💨💨💨💨💨💨

exchanges/request/request.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@gloriousCode gloriousCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking with closing the reader... 😄
Nice work programmers @cranktakular & @shazbert tACK

@gloriousCode gloriousCode added the gcrc GloriousCode Review Complete label Mar 24, 2024
Copy link
Collaborator

@thrasher- thrasher- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch @cranktakular ! Thanks @shazbert

@thrasher- thrasher- merged commit 05dec88 into thrasher-corp:master Mar 25, 2024
4 of 10 checks passed
@shazbert shazbert deleted the request_race branch May 3, 2024 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug gcrc GloriousCode Review Complete review me This pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants