Skip to content

Add creation tracebacks to unclosed warnings#12691

Open
nightcityblade wants to merge 2 commits into
aio-libs:masterfrom
nightcityblade:fix/issue-11235
Open

Add creation tracebacks to unclosed warnings#12691
nightcityblade wants to merge 2 commits into
aio-libs:masterfrom
nightcityblade:fix/issue-11235

Conversation

@nightcityblade
Copy link
Copy Markdown
Contributor

What do these changes do?

Include the object creation traceback in unclosed resource warning messages when the event loop is running in debug mode.

Are there changes in behavior for the user?

Yes. In debug mode, unclosed ClientSession, connection, connector, and response warnings now include where the object was created, making leaks easier to trace. Non-debug behavior is unchanged.

Is it a substantial burden for the maintainers to support this?

No. This reuses the existing _source_traceback captured in debug mode and keeps the formatting in a small helper shared by the existing unclosed-resource warnings.

Related issue number

Fixes #11235.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is .
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label May 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.95%. Comparing base (d2c203f) to head (ccc61b1).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12691   +/-   ##
=======================================
  Coverage   98.95%   98.95%           
=======================================
  Files         131      131           
  Lines       46688    46697    +9     
  Branches     2421     2422    +1     
=======================================
+ Hits        46200    46209    +9     
  Misses        366      366           
  Partials      122      122           
Flag Coverage Δ
Autobahn 22.42% <16.66%> (-0.01%) ⬇️
CI-GHA 98.92% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.67% <100.00%> (-0.02%) ⬇️
OS-Windows 97.04% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.93% <100.00%> (-0.01%) ⬇️
Py-3.10 98.15% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.41% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.50% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.48% <100.00%> (+<0.01%) ⬆️
Py-3.14 98.50% <100.00%> (+<0.01%) ⬆️
Py-3.14t 97.55% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 97.42% <75.00%> (-0.02%) ⬇️
VM-macos 97.93% <100.00%> (-0.01%) ⬇️
VM-ubuntu 98.67% <100.00%> (-0.02%) ⬇️
VM-windows 97.04% <100.00%> (+<0.01%) ⬆️
cython-coverage 37.94% <25.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 25, 2026

Merging this PR will not alter performance

✅ 72 untouched benchmarks
⏩ 72 skipped benchmarks1


Comparing nightcityblade:fix/issue-11235 (ccc61b1) with master (d2c203f)

Open in CodSpeed

Footnotes

  1. 72 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show where garbaged object was instantiated in warnings

1 participant