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
gh-98253: fix refleak issue in typing.py #98591
base: main
Are you sure you want to change the base?
Conversation
|
PS: It would be good to merge this not only in Python 3.12, but also older versions (3.11, 3.10, 3.9, 3.8). |
3.8 and 3.9 are now only accepting security-related patches, so this definitely won't be backported that far, I'm afraid. |
Fair enough. In that case, I propose to target 3.10, 3.11, and 3.12. |
|
As mentioned in the issue I'm skeptical that this is something we should fix in typing.py. I'll ask for input from other core devs (after the dust from the 3.11 release settles). |
|
I'm skeptical too. I feel that the tool is incorrectly blaming typing.py. |
|
@gvanrossum, did you see the discussion in #98253? When I first reported the issue, the actual source of these refleaks was mysterious. Further along the discussion thread, the problem was finally tracked down (see post #98253 (comment)) The problem is that the caching mechanism in The patch in this PR is simple and it breaks this problematic chain of references. Of course, one could say: let's leave |


The
typingmodule internally uses LRU caches to memoize the result oftype-related computations. These LRU caches have the potential to introduce
difficult-to-find reference leaks spanning multiple extension modules.
Suppose that a binary extension module
aleaks a reference to a typea.Awith typed function signatures.
The leaked type
a.Awill induce a secondary refleak of thetypingLRUcaches, which will at this point cause tertiary leaks in entirely unrelated
extension modules. In this way, a benign refleak in any extension can cause
difficult-to-debug leaks everywhere else.
This commit fixes this by removing the direct reference from
a.Atotypingimplementation details.