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

fix sub-subsegment datarace #61

Merged
merged 1 commit into from
Jul 20, 2018
Merged

Conversation

t-yuki
Copy link
Contributor

@t-yuki t-yuki commented Jul 19, 2018

There is a data-race condition in xray.BeginSubsegment function, the line seg.ParentSegment.totalSubSegments++ because seg.ParentSegement isn't locked well for deeply nested segments.

Without this change, the test will cause the below:

=== RUN   TestSubsegmentDataRace
==================
WARNING: DATA RACE
Read at 0x00c42037f218 by goroutine 93:
  github.com/aws/aws-xray-sdk-go/xray.BeginSubsegment()
      /home/t-yuki/go/src/github.com/aws/aws-xray-sdk-go/xray/segment.go:188 +0x408
  github.com/aws/aws-xray-sdk-go/xray.TestSubsegmentDataRace.func1()
      /home/t-yuki/go/src/github.com/aws/aws-xray-sdk-go/xray/segment_test.go:40 +0xcf

Previous write at 0x00c42037f218 by goroutine 95:
  github.com/aws/aws-xray-sdk-go/xray.BeginSubsegment()
      /home/t-yuki/go/src/github.com/aws/aws-xray-sdk-go/xray/segment.go:188 +0x42a
  github.com/aws/aws-xray-sdk-go/xray.TestSubsegmentDataRace.func1()
      /home/t-yuki/go/src/github.com/aws/aws-xray-sdk-go/xray/segment_test.go:39 +0x98

Goroutine 93 (running) created at:
  github.com/aws/aws-xray-sdk-go/xray.TestSubsegmentDataRace()
      /home/t-yuki/go/src/github.com/aws/aws-xray-sdk-go/xray/segment_test.go:37 +0x1f9
  testing.tRunner()
      /home/t-yuki/go/tools/go/src/testing/testing.go:746 +0x16c

Goroutine 95 (running) created at:
  github.com/aws/aws-xray-sdk-go/xray.TestSubsegmentDataRace()
      /home/t-yuki/go/src/github.com/aws/aws-xray-sdk-go/xray/segment_test.go:37 +0x1f9
  testing.tRunner()
      /home/t-yuki/go/tools/go/src/testing/testing.go:746 +0x16c
==================

Also I included a test tweak for TestCaptureAsync to suppress undesirable data-race detection.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@luluzhao luluzhao merged commit 7695d38 into aws:master Jul 20, 2018
@luluzhao
Copy link
Contributor

I merged this PR. Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants