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(tracing): add flag for aiohttp that disables potential for memory leak #12081

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ZStriker19
Copy link
Contributor

@ZStriker19 ZStriker19 commented Jan 24, 2025

This PR adds the environment variable DD_AIOHTTP_CLIENT_DISABLE_STREAM_TIMING_FOR_MEM_LEAK to address a potential memory leak in the aiohttp integration. When set to true, this flag may cause streamed response span timing to be inaccurate. The flag defaults to false.

When this was merged #7551 we essentially added support for getting the correct timing of streamed responses, however it also caused us to sometimes never close spans, which lead to a memory leak. When set to true, this flag essentially reverts that behavior.

Checklist

  • PR author has checked that all the criteria below are met
  • The PR description includes an overview of the change
  • The PR description articulates the motivation for the change
  • The change includes tests OR the PR description describes a testing strategy
  • The PR description notes risks associated with the change, if any
  • Newly-added code is easy to change
  • The change follows the library release note guidelines
  • The change includes or references documentation updates if necessary
  • Backport labels are set (if applicable)

Reviewer Checklist

  • Reviewer has checked that all the criteria below are met
  • Title is accurate
  • All changes are related to the pull request's stated goal
  • Avoids breaking API changes
  • Testing strategy adequately addresses listed risks
  • Newly-added code is easy to change
  • Release note makes sense to a user of the library
  • If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment
  • Backport labels are set in a manner that is consistent with the release branch maintenance policy

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 12.43%. Comparing base (b90fa38) to head (426f466).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12081      +/-   ##
==========================================
- Coverage   12.98%   12.43%   -0.56%     
==========================================
  Files        1607     1607              
  Lines      136979   136979              
==========================================
- Hits        17782    17028     -754     
- Misses     119197   119951     +754     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ZStriker19 ZStriker19 changed the title feat: add flag for aiohttp that disables potential memory leak but makes stream response time incorrect feat(tracing): add flag for aiohttp that disables potential memory leak but makes stream response time incorrect Jan 24, 2025
Copy link
Contributor

github-actions bot commented Jan 24, 2025

CODEOWNERS have been resolved as:

releasenotes/notes/add_aiohttp_memory_leak_flag-66005f987dbfbd47.yaml   @DataDog/apm-python
ddtrace/contrib/internal/aiohttp/middlewares.py                         @DataDog/apm-core-python @DataDog/apm-idm-python
ddtrace/contrib/internal/aiohttp/patch.py                               @DataDog/apm-core-python @DataDog/apm-idm-python

# todo: this is a temporary fix for a memory leak in aiohttp. We should find a way to
# consistently close spans with the correct timing.
if not config.aiohttp["disable_stream_timing_for_mem_leak"]:
if type(response) is web.StreamResponse and not response.task.done():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

use isintance() instead of type() (...read more)

Using isinstance is faster than type but also consider inheritance, which makes it more accurate.

View in Datadog  Leave us feedback  Documentation

@ZStriker19 ZStriker19 changed the title feat(tracing): add flag for aiohttp that disables potential memory leak but makes stream response time incorrect fix(tracing): add flag for aiohttp that disables potential memory leak but makes stream response time incorrect Jan 24, 2025
@datadog-dd-trace-py-rkomorn
Copy link

datadog-dd-trace-py-rkomorn bot commented Jan 24, 2025

Datadog Report

Branch report: zachg/add_aiohttp_flag_for_stream_response_time
Commit report: 52cad7f
Test service: dd-trace-py

✅ 0 Failed, 130 Passed, 1378 Skipped, 4m 17.29s Total duration (35m 49.93s time saved)

@ZStriker19 ZStriker19 changed the title fix(tracing): add flag for aiohttp that disables potential memory leak but makes stream response time incorrect fix(tracing): add flag for aiohttp that disables potential for memory leak Jan 24, 2025
@pr-commenter
Copy link

pr-commenter bot commented Jan 24, 2025

Benchmarks

Benchmark execution time: 2025-01-24 23:15:39

Comparing candidate commit 52cad7f in PR branch zachg/add_aiohttp_flag_for_stream_response_time with baseline commit 1811db1 in branch main.

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

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