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

ddtrace/mocktracer: use lock in String method #2229

Merged
merged 2 commits into from
Sep 25, 2023

Conversation

phoenix2x
Copy link
Contributor

What does this PR do?

Use RLock in the mockspan String method to fix the "data race" error when running tests with -race flag. All other methods do use lock so this seems to be an oversight.

Motivation

WARNING: DATA RACE
Write at 0x00c00039b650 by goroutine 16:
  runtime.mapassign_faststr()
      /usr/local/go/src/runtime/map_faststr.go:203 +0x0
  gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer.(*mockspan).SetTag()
      /home/circleci/project/vendor/gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer/mockspan.go:130 +0x304
Previous read at 0x00c00039b650 by goroutine 28:
  reflect.maplen()
      /usr/local/go/src/runtime/map.go:1394 +0x0
  reflect.Value.lenNonSlice()
      /usr/local/go/src/reflect/value.go:1630 +0x26d
  reflect.Value.Len()
      /usr/local/go/src/reflect/value.go:1619 +0x11a
  internal/fmtsort.Sort()
      /usr/local/go/src/internal/fmtsort/sort.go:58 +0x101
  fmt.(*pp).printValue()
      /usr/local/go/src/fmt/print.go:800 +0x1164
  fmt.(*pp).printArg()
      /usr/local/go/src/fmt/print.go:743 +0xe17
  fmt.(*pp).doPrintf()
      /usr/local/go/src/fmt/print.go:1057 +0x499
  fmt.Sprintf()
      /usr/local/go/src/fmt/print.go:219 +0x67
  gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer.(*mockspan).String()
      /home/circleci/project/vendor/gopkg.in/DataDog/dd-trace-go.v1/ddtrace/mocktracer/mockspan.go:221 +0x22a

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@phoenix2x phoenix2x requested a review from a team September 21, 2023 19:20
Copy link
Contributor

@katiehockman katiehockman left a comment

Choose a reason for hiding this comment

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

Thank you!!

@katiehockman
Copy link
Contributor

/merge

@dd-devflow
Copy link

dd-devflow bot commented Sep 25, 2023

🚂 MergeQueue

This merge request is not mergeable yet, because of pending checks/missing approvals. It will be added to the queue as soon as checks pass and/or get approvals. You can remove it from the waiting list with /remove command.

you can cancel this operation by commenting your pull request with /merge -c!

@dd-devflow
Copy link

dd-devflow bot commented Sep 25, 2023

🚂 MergeQueue

Added to the queue.

This build is going to start soon! (estimated merge in less than 8m)

you can cancel this operation by commenting your pull request with /merge -c!

@dd-mergequeue dd-mergequeue bot merged commit 6a938b3 into DataDog:main Sep 25, 2023
11 checks passed
@phoenix2x phoenix2x deleted the mockspan-fix-race-error branch September 26, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants