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

asyncio: fix duplicate instrumentation #3408

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

bourbonkk
Copy link
Contributor

Description

This PR addresses duplicate instrumentation of Future objects when using AsyncioInstrumentor multiple times on the same Future. Without proper de-duplication, callbacks can continue to accumulate and cause memory leaks. This change introduces a simple attribute check on each Future, coroutine, or function so that once instrumented, no additional callbacks or spans will be attached.

Fixes #3383 aiokafka instrumentation cause memory leak

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Unit Tests:
    • Added a new test file (test_asyncio_duplicate_instrument.py) which repeatedly calls trace_future on the same Future objects.
    • Verified that the callback count does not grow beyond a small constant (1–2 callbacks).
  • Manual Verification:
    • Mocked up a simple scenario mimicking aiokafka.GroupCoordinator usage, confirming that repeated instrumentation does not cause exponential callback growth.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link

linux-foundation-easycla bot commented Apr 4, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@xrmx xrmx changed the title #3383 fix duplicate instrument asyncio: fix duplicate instrumentation Apr 4, 2025
@xrmx
Copy link
Contributor

xrmx commented Apr 4, 2025

@bourbonkk looks like you commited with multiple accounts and one has not signed the CLA

@bourbonkk bourbonkk requested a review from a team as a code owner April 4, 2025 07:54
@bourbonkk bourbonkk closed this Apr 4, 2025
@bourbonkk bourbonkk reopened this Apr 4, 2025
@bourbonkk bourbonkk removed their assignment Apr 4, 2025
Copy link

@yonathan-wolloch-lendbuzz yonathan-wolloch-lendbuzz left a comment

Choose a reason for hiding this comment

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

Thank you!

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.

aiokafka instrumentation cause memory leak
4 participants