Skip to content

Guard Garbage Collection Metrics Against Re-Entrant Calls#1707

Open
TimPansino wants to merge 4 commits intomainfrom
fix-gc-metrics
Open

Guard Garbage Collection Metrics Against Re-Entrant Calls#1707
TimPansino wants to merge 4 commits intomainfrom
fix-gc-metrics

Conversation

@TimPansino
Copy link
Copy Markdown
Contributor

Overview

  • Add flag to prevent re-entrant calls to _GCDataSource.record_gc() to prevent infinite recursion on Python 3.13+.
  • Improve caching of IS_PYPY in gc_data.py for performance.
  • Add regression test that bypasses garbage collection infrastructure and directly unit tests re-entrant calls to _GCDataSource.record_gc().
    • If we can find a reliable way to trigger the original issue in testing, we could add a better regression test here as well.

Related Github Issue

Closes #1706

Testing

  1. Revert the changes made to gc_data.py.
  2. Run the agent_unittests suite. Observe the tests hanging forever when simulating re-entrant invocations of record_gc.
  3. Restore the changes to gc_data.py.
  4. Run the agent_unittests suite. Observe the tests passing due to the new guard in place preventing re-entrant calls.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ ACTION actionlint 8 0 0 1.18s
✅ MARKDOWN markdownlint 7 0 0 0 1.27s
✅ PYTHON ruff 1030 0 0 0 1.36s
✅ PYTHON ruff-format 1030 0 0 0 0.42s
✅ YAML prettier 19 0 0 0 1.5s
✅ YAML v8r 19 0 0 5.88s
✅ YAML yamllint 19 0 0 0.77s

See detailed reports in MegaLinter artifacts

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@mergify mergify bot added the tests-failing Tests failing in CI. label Apr 9, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 86.36364% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.91%. Comparing base (77df266) to head (d63e8fe).

Files with missing lines Patch % Lines
newrelic/samplers/gc_data.py 86.36% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1707      +/-   ##
==========================================
- Coverage   81.97%   81.91%   -0.06%     
==========================================
  Files         214      214              
  Lines       25803    25810       +7     
  Branches     4082     4083       +1     
==========================================
- Hits        21151    21142       -9     
- Misses       3261     3272      +11     
- Partials     1391     1396       +5     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TimPansino TimPansino marked this pull request as ready for review April 9, 2026 22:12
@TimPansino TimPansino requested a review from a team as a code owner April 9, 2026 22:12
@TimPansino TimPansino requested a review from hmstepanek April 9, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests-failing Tests failing in CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RecursionError in GC sampler callback on Python 3.13 (re-entrant gc_data.record_gc)

3 participants