bpo-38006: Clear weakrefs in garbage found by the GC#16495
bpo-38006: Clear weakrefs in garbage found by the GC#16495ambv merged 1 commit intopython:masterfrom
Conversation
Fix a bug due to the interaction of weakrefs and the cyclic garbage collector. We must clear any weakrefs in garbage in order to prevent their callbacks from executing and causing a crash.
|
@ambv: Please replace |
|
GH-16499 is a backport of this pull request to the 3.8 branch. |
|
Should we backport to all maintained branches? I think it applies even to 2.7. |
Ya, these holes have been there since the day weakrefs were added to the language. |
Fix a bug due to the interaction of weakrefs and the cyclic garbage collector. We must clear any weakrefs in garbage in order to prevent their callbacks from executing and causing a crash. (cherry picked from commit bcda460) Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
|
Uh, I'm a bit anxious about this. This is added to workaround a crash that's caused by a container not implementing the GC protocol correctly. But in turn it may silence the invocation of many legitimate weakref callbacks. Weakref callbacks are often used to release external resources (for example system resources). This is actually the original motivation for weakref.finalize, which was originally a I may be misreading the patch, but if a Edit: ok, I read through the "Headache time" part and it's clearer now :-) My bad. |
|
To be sure we're on the same page, it was always the case that we suppressed callbacks from trash weakrefs. If the user wants the callback to be invoked for sure, it's the user's responsibility to ensure the weakref outlives the referent. What did change is that a missing I bet we could run more callbacks now, since you added a pass to abort the gc run if trash got resurrected. But I never heard anyone ask for that, and don't want it myself 😉 |
Fix a bug due to the interaction of weakrefs and the cyclic garbage collector. We must clear any weakrefs in garbage in order to prevent their callbacks from executing and causing a crash.
Fix a bug due to the interaction of weakrefs and the cyclic garbage
collector. We must clear any weakrefs in garbage in order to prevent
their callbacks from executing and causing a crash.
https://bugs.python.org/issue38006