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/tracer: address race detector warning from TestDefaultHTTPClient #1347

Merged
merged 1 commit into from Jun 18, 2022

Conversation

nsrip-dd
Copy link
Contributor

Doing a deep comparision (through assert.Equal/assert.NotEqual) of
*http.Clients in these tests can trigger a race detector warning:

=== FAIL: ddtrace/tracer TestDefaultHTTPClient/socket (0.00s)
==================
WARNING: DATA RACE
Read at 0x000001e0a080 by goroutine 123:
  [ ... elided ... ]
  reflect.DeepEqual()
      /usr/local/Cellar/go/1.18.3/libexec/src/reflect/deepequal.go:237 +0x3f9
  github.com/stretchr/testify/assert.ObjectsAreEqual()
      /Users/nick.ripley/go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:65 +0x184
  github.com/stretchr/testify/assert.NotEqual()
      /Users/nick.ripley/go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:694 +0x204
  gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer.TestDefaultHTTPClient.func2()
      /Users/nick.ripley/dd/dd-trace-go/ddtrace/tracer/option_test.go:433 +0x3a4
  testing.tRunner()
      /usr/local/Cellar/go/1.18.3/libexec/src/testing/testing.go:1439 +0x213
  testing.(*T).Run.func1()
      /usr/local/Cellar/go/1.18.3/libexec/src/testing/testing.go:1486 +0x47

Previous write at 0x000001e0a080 by goroutine 19:
  sync/atomic.AddInt32()
      /usr/local/Cellar/go/1.18.3/libexec/src/runtime/race_amd64.s:279 +0xb
  sync/atomic.AddInt32()
      <autogenerated>:1 +0x1a
  net/http.(*Transport).removeIdleConn.func1()
      /usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:1096 +0x39
  runtime.deferreturn()
      /usr/local/Cellar/go/1.18.3/libexec/src/runtime/panic.go:436 +0x32
  net/http.(*persistConn).readLoop.func1()
      /usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:2062 +0x72
  runtime.deferreturn()
      /usr/local/Cellar/go/1.18.3/libexec/src/runtime/panic.go:436 +0x32
  net/http.(*Transport).dialConn.func5()
      /usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:1750 +0x39

This is a data race but not actually a bug in the tracer library, just a bug in
the tests. We can use assert.Same/assert.NotSame to compare the
*http.Clients as pointers, since the tests are just checking whether or not
the default client is returned.

Doing a deep comparision (through assert.Equal/assert.NotEqual) of
http.Clients in these tests can trigger a race detector warning:

	=== FAIL: ddtrace/tracer TestDefaultHTTPClient/socket (0.00s)
	==================
	WARNING: DATA RACE
	Read at 0x000001e0a080 by goroutine 123:
	  [ ... elided ... ]
	  reflect.DeepEqual()
	      /usr/local/Cellar/go/1.18.3/libexec/src/reflect/deepequal.go:237 +0x3f9
	  github.com/stretchr/testify/assert.ObjectsAreEqual()
	      /Users/nick.ripley/go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:65 +0x184
	  github.com/stretchr/testify/assert.NotEqual()
	      /Users/nick.ripley/go/pkg/mod/github.com/stretchr/testify@v1.7.0/assert/assertions.go:694 +0x204
	  gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer.TestDefaultHTTPClient.func2()
	      /Users/nick.ripley/dd/dd-trace-go/ddtrace/tracer/option_test.go:433 +0x3a4
	  testing.tRunner()
	      /usr/local/Cellar/go/1.18.3/libexec/src/testing/testing.go:1439 +0x213
	  testing.(*T).Run.func1()
	      /usr/local/Cellar/go/1.18.3/libexec/src/testing/testing.go:1486 +0x47

	Previous write at 0x000001e0a080 by goroutine 19:
	  sync/atomic.AddInt32()
	      /usr/local/Cellar/go/1.18.3/libexec/src/runtime/race_amd64.s:279 +0xb
	  sync/atomic.AddInt32()
	      <autogenerated>:1 +0x1a
	  net/http.(*Transport).removeIdleConn.func1()
	      /usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:1096 +0x39
	  runtime.deferreturn()
	      /usr/local/Cellar/go/1.18.3/libexec/src/runtime/panic.go:436 +0x32
	  net/http.(*persistConn).readLoop.func1()
	      /usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:2062 +0x72
	  runtime.deferreturn()
	      /usr/local/Cellar/go/1.18.3/libexec/src/runtime/panic.go:436 +0x32
	  net/http.(*Transport).dialConn.func5()
	      /usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:1750 +0x39

This is a data race but not actually a bug in the tracer library, just a
bug in the tests. We can use assert.Same/assert.NotSame to compare the
*http.Clients as pointers, since the tests are just checking whether or
not the default client is returned.
@nsrip-dd nsrip-dd requested a review from a team June 17, 2022 17:13
@nsrip-dd nsrip-dd added this to the Triage milestone Jun 17, 2022
@nsrip-dd nsrip-dd merged commit 0870477 into main Jun 18, 2022
@nsrip-dd nsrip-dd deleted the nick.ripley/fix-ddtrace-race-warning branch June 18, 2022 02:10
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.

None yet

2 participants