-
Notifications
You must be signed in to change notification settings - Fork 591
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 and detect race condition in clienttrace.go #5700
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import ( | |
"fmt" | ||
"net/http" | ||
"net/http/httptrace" | ||
"sync" | ||
"testing" | ||
|
||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" | ||
) | ||
|
@@ -32,3 +34,45 @@ func ExampleNewClientTrace() { | |
|
||
fmt.Println(resp.Status) | ||
} | ||
|
||
type zeroTripper struct{} | ||
|
||
func (zeroTripper) RoundTrip(_ *http.Request) (*http.Response, error) { | ||
return &http.Response{StatusCode: 200}, nil | ||
} | ||
|
||
var _ http.RoundTripper = zeroTripper{} | ||
|
||
// TestNewClientParallelismWithoutSubspans tests running many Gets on a client simultaneously, | ||
// which would trigger a race condition if root were not protected by a mutex. | ||
func TestNewClientParallelismWithoutSubspans(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test passes when run against main:
It does not seem to be testing the fix being applied here. |
||
t.Parallel() | ||
|
||
makeClientTrace := func(ctx context.Context) *httptrace.ClientTrace { | ||
return NewClientTrace(ctx, WithoutSubSpans()) | ||
} | ||
|
||
client := http.Client{ | ||
Transport: otelhttp.NewTransport( | ||
zeroTripper{}, | ||
otelhttp.WithClientTrace(makeClientTrace), | ||
), | ||
} | ||
|
||
var wg sync.WaitGroup | ||
|
||
for i := 1; i < 10000; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lot of goroutines being spawned here. What's the reasoning behind this? It is making this test quite resource intensive. |
||
wg.Add(1) | ||
go func() { | ||
resp, err := client.Get("}}}}}") | ||
if err != nil { | ||
t.Error(err) | ||
return | ||
} | ||
resp.Body.Close() | ||
wg.Done() | ||
}() | ||
} | ||
|
||
wg.Wait() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is what is breaking
opentelemetry-go-contrib/instrumentation/net/http/httptrace/otelhttptrace/test/clienttrace_test.go
Lines 239 to 251 in b0dce52
https://github.com/open-telemetry/opentelemetry-go-contrib/actions/runs/9620444944/job/26539940748?pr=5700