Skip to content

contrib/{internal/httptrace, net/http}: fix memory leak and request closure #2138

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

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

knusbaum
Copy link
Contributor

@knusbaum knusbaum commented Jul 20, 2023

What does this PR do?

This pull request addresses one major and one minor performance issue.

The major issue is in contrib/net/http, where (*ServeMux).ServeHTTP adds
an element to it's spanOpts slice every time a request is served. This is
both a race, and it grows the slice unbounded resulting in a memory leak,
and a huge amount of CPU time spent copying the slice.

The second, smaller issues is in contrib/internal/httptrace's
HeaderTagsFromRequest. This function created a closure which captured the
request including all of its headers. This may keep the request alive
longer than necessary. Instead we build the list of required headers and
return a function closing over just that list.

Reviewer's Checklist

  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
Julio-Guerra Julio Guerra
…losure

This pull request addresses one major and one minor performance issue.

The major issue is in contrib/net/http, where (*ServeMux).ServeHTTP adds
an element to it's spanOpts slice every time a request is served. This is
both a race, and it grows the slice unbounded resulting in a memory leak,
and a huge amount of CPU time spent copying the slice.

The second, smaller issues is in contrib/internal/httptrace's
HeaderTagsFromRequest. This function created a closure which captured the
request including all of its headers. This may keep the request alive
longer than necessary. Instead we build the list of required headers and
return a function closing over just that list.
@knusbaum knusbaum requested a review from a team July 20, 2023 20:50
@pr-commenter
Copy link

pr-commenter bot commented Jul 20, 2023

Benchmarks

Benchmark execution time: 2023-07-20 20:59:58

Comparing candidate commit cddc98c in PR branch knusbaum/perf-fix with baseline commit 41fe21f in branch release-v1.53.x.

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

@knusbaum knusbaum merged commit b992189 into release-v1.53.x Jul 20, 2023
@knusbaum knusbaum deleted the knusbaum/perf-fix branch July 20, 2023 21:01
knusbaum added a commit that referenced this pull request Jul 20, 2023

Verified

This commit was signed with the committer’s verified signature.
Julio-Guerra Julio Guerra
…losure (#2138)

This pull request addresses one major and one minor performance issue.

The major issue is in contrib/net/http, where (*ServeMux).ServeHTTP adds
an element to it's spanOpts slice every time a request is served. This is
both a race, and it grows the slice unbounded resulting in a memory leak,
and a huge amount of CPU time spent copying the slice.

The second, smaller issues is in contrib/internal/httptrace's
HeaderTagsFromRequest. This function created a closure which captured the
request including all of its headers. This may keep the request alive
longer than necessary. Instead we build the list of required headers and
return a function closing over just that list.
knusbaum added a commit that referenced this pull request Jul 25, 2023

Verified

This commit was signed with the committer’s verified signature.
Julio-Guerra Julio Guerra
…losure (cherry-pick #2138) (#2139)

This pull request addresses one major and one minor performance issue.

The major issue is in contrib/net/http, where (*ServeMux).ServeHTTP adds
an element to it's spanOpts slice every time a request is served. This is
both a race, and it grows the slice unbounded resulting in a memory leak,
and a huge amount of CPU time spent copying the slice.

The second, smaller issues is in contrib/internal/httptrace's
HeaderTagsFromRequest. This function created a closure which captured the
request including all of its headers. This may keep the request alive
longer than necessary. Instead we build the list of required headers and
return a function closing over just that list.

This cherry-picks #2138
katiehockman pushed a commit that referenced this pull request Jul 26, 2023

Verified

This commit was signed with the committer’s verified signature.
Julio-Guerra Julio Guerra
…losure (cherry-pick #2138) (#2139)

This pull request addresses one major and one minor performance issue.

The major issue is in contrib/net/http, where (*ServeMux).ServeHTTP adds
an element to it's spanOpts slice every time a request is served. This is
both a race, and it grows the slice unbounded resulting in a memory leak,
and a huge amount of CPU time spent copying the slice.

The second, smaller issues is in contrib/internal/httptrace's
HeaderTagsFromRequest. This function created a closure which captured the
request including all of its headers. This may keep the request alive
longer than necessary. Instead we build the list of required headers and
return a function closing over just that list.

This cherry-picks #2138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants