Skip to content

contrib/net/http: Copy span options and resource name to avoid data race#2204

Merged
ajgajg1134 merged 4 commits into
mainfrom
andrew.glaude/HttpRace
Sep 6, 2023
Merged

contrib/net/http: Copy span options and resource name to avoid data race#2204
ajgajg1134 merged 4 commits into
mainfrom
andrew.glaude/HttpRace

Conversation

@ajgajg1134

@ajgajg1134 ajgajg1134 commented Sep 5, 2023

Copy link
Copy Markdown
Contributor

What does this PR do?

Found a few data races in how we handle span options.

Motivation

The data race here could result in clobbered start span options for concurrent HTTP requests.

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!

Comment thread contrib/net/http/http_test.go Outdated
Comment thread contrib/net/http/http_test.go Outdated
@pr-commenter

pr-commenter Bot commented Sep 5, 2023

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2023-09-06 14:13:21

Comparing candidate commit c2958d2 in PR branch andrew.glaude/HttpRace with baseline commit 3ebb83f in branch main.

Found 3 performance improvements and 0 performance regressions! Performance is the same for 37 metrics, 1 unstable metrics.

scenario:BenchmarkHttpServeTrace-24

  • 🟩 allocated_mem [-915 bytes; -913 bytes] or [-15.616%; -15.584%]
  • 🟩 allocations [-16; -16] or [-23.188%; -23.188%]
  • 🟩 execution_time [-1.417µs; -1.260µs] or [-11.833%; -10.523%]

@ajgajg1134

Copy link
Copy Markdown
Contributor Author

Benchmarks

Benchmark execution time: 2023-09-05 19:05:24

Comparing candidate commit fcd71d6 in PR branch andrew.glaude/HttpRace with baseline commit c66772b in branch main.

Found 3 performance improvements and 0 performance regressions! Performance is the same for 37 metrics, 1 unstable metrics.

scenario:BenchmarkHttpServeTrace-24

  • 🟩 allocated_mem [-916 bytes; -915 bytes] or [-15.630%; -15.608%]
  • 🟩 allocations [-16; -16] or [-23.188%; -23.188%]
  • 🟩 execution_time [-1.504µs; -1.418µs] or [-12.625%; -11.905%]

These aren't real performance improvements. They appear here because the benchmark was improved to focus on the ServeHTTP function.

@ajgajg1134
ajgajg1134 marked this pull request as ready for review September 5, 2023 19:39
@ajgajg1134
ajgajg1134 requested a review from a team September 5, 2023 19:39
@ajgajg1134
ajgajg1134 merged commit 3a403a7 into main Sep 6, 2023
@ajgajg1134
ajgajg1134 deleted the andrew.glaude/HttpRace branch September 6, 2023 15:08
nsrip-dd added a commit that referenced this pull request Sep 9, 2024
With Go 1.23 released on 2024-08-13, we drop support for Go 1.21. This
means Go 1.22 is now our minimum supported Go release. Update our CI
files to reflect our current supported Go versions, and remove pre-Go
1.22 workarounds.

In addition to the CI bumps, this PR changes/fixes a few things related to the upgrade:

- Drops the old `rand` from the tracer, now that we can depend on `math/rand/v2`.
- Uses `slices` in the appsec package.
- The `TestWrapHandlerWithResourceNameNoRace` got a new data race. Specifically,
  by bumping our `go.mod` to 1.22, we get the new 1.22 ServeMux behavior internally.
  The 1.22 ServeMux modifies the Request, introducing a race with all the goroutines
  accessing/modifying the request concurrently. Fix it by giving each goroutine its own
  request. I verified that the test still catches the intended bug by reverting the fix from
  #2204 and verifying that the test fails.
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