Skip to content

Fix weakref garbage collection race condition in DNS resolver manager #10923

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 3 commits into from
May 21, 2025

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented May 21, 2025

Fix AttributeError: NoneType object has no attribute cancel in DNS resolver cleanup

Downstream users reported a crash during test teardown with the following error:

AttributeError: NoneType object has no attribute cancel

The issue occurs in _DNSResolverManager.release_resolver() when the weakref-managed resolver object gets garbage collected before it can be properly cancelled. This creates a race condition where the resolver reference becomes None but the cleanup code still tries to call resolver.cancel().

bdraco added 2 commits May 21, 2025 18:57
Fix `AttributeError: NoneType object has no attribute cancel` in DNS resolver cleanup

Downstream users reported a crash during test teardown with the following error:

```
AttributeError: NoneType object has no attribute cancel
```

The issue occurs in `_DNSResolverManager.release_resolver()` when the weakref-managed resolver object gets garbage collected before it can be properly cancelled. This creates a race condition where the resolver reference becomes `None` but the cleanup code still tries to call `resolver.cancel()`.
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 21, 2025
@bdraco bdraco added backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot and removed bot:chronographer:provided There is a change note present in this PR labels May 21, 2025
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label May 21, 2025
Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.75%. Comparing base (b58c3ad) to head (33344ac).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10923   +/-   ##
=======================================
  Coverage   98.75%   98.75%           
=======================================
  Files         129      129           
  Lines       39072    39095   +23     
  Branches     2164     2166    +2     
=======================================
+ Hits        38586    38609   +23     
  Misses        337      337           
  Partials      149      149           
Flag Coverage Δ
CI-GHA 98.64% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.35% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.50% <100.00%> (-0.01%) ⬇️
OS-macOS 97.50% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.39% <100.00%> (+<0.01%) ⬆️
Py-3.10.17 97.93% <100.00%> (+<0.01%) ⬆️
Py-3.11.12 97.96% <100.00%> (-0.05%) ⬇️
Py-3.11.9 97.47% <100.00%> (+<0.01%) ⬆️
Py-3.12.10 98.41% <100.00%> (-0.01%) ⬇️
Py-3.13.3 98.40% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.26% <100.00%> (+<0.01%) ⬆️
Py-3.9.22 97.79% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 87.57% <100.00%> (-5.37%) ⬇️
VM-macos 97.50% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.35% <100.00%> (+<0.01%) ⬆️
VM-windows 96.50% <100.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.

Copy link

codspeed-hq bot commented May 21, 2025

CodSpeed Performance Report

Merging #10923 will not alter performance

Comparing too_weak (33344ac) with master (b58c3ad)

Summary

✅ 59 untouched benchmarks

@bdraco bdraco marked this pull request as ready for review May 21, 2025 23:16
@bdraco bdraco requested review from webknjaz and asvetlov as code owners May 21, 2025 23:16
@bdraco bdraco merged commit 19643c9 into master May 21, 2025
40 checks passed
@bdraco bdraco deleted the too_weak branch May 21, 2025 23:16
Copy link
Contributor

patchback bot commented May 21, 2025

Backport to 3.12: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.12/19643c9cfe734ced3d2a821aa53c7f30c737a097/pr-10923

Backported as #10924

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request May 21, 2025
bdraco added a commit that referenced this pull request May 21, 2025
…ce condition in DNS resolver manager (#10924)

Co-authored-by: J. Nick Koston <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot 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.

1 participant