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
Removing thread reference in thread results in leaked reference #86429
Comments
In bpo-37193, I'd worked on an implementation in which a thread reference would be removed as the thread was closing, but this led to a memory leak caught by the buildbots (https://bugs.python.org/issue37193#msg380172). As I tracked down the issue in #67316, I discovered that removing the reference to the thread from within the thread triggered the reference leak detection. I've distilled that behavior into its own test which fails on master:
Running that test with refcount checks leads to this failure:
Is that behavior by design? Is it simply not possible to remove a reference to a thread from within the thread? |
Could this be a race condition? The thread that's created in the test is not waited on (join), it may or may not have exited by the time the test function returns. |
I don't think it's a race condition for two reasons: adding a If you join the thread in the test, the leak is not detected. However, I believe that's because, in order to join on the thread, you must also hold a handle to the thread, so the condition isn't triggered. |
Maybe this is related to (or duplicate of) bpo-37788? Python 3.7 has a regression where threads that are never joined cause leaks; previous code was written assuming you didn't need to join threads. Do you still see the leak even if you don't clear the "threads" list (change the target to a no-op), or if you never create a list in the first place? |
Yes, I agree it's a duplicate of bpo-37788. And yes, it does still leak if the list is never created or if the target is a no-op. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: