-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
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-128679: Fix tracemalloc.stop() race conditions #128893
Conversation
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(), _PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check tracemalloc_config.tracing after calling TABLES_LOCK(). _PyTraceMalloc_TraceRef() now always returns 0.
@ZeroIntensity: Ok, here is the new fix for #128679 tracemalloc.stop() race condition. Thanks to #128888 refactoring, the fix is simpler and should be more reliable than my previous attempt. Moreover, this fix is more complete: I fixed more functions. |
For the test, I prefer to use |
Ok, that makes sense. We might want to expose that publicly at some point, FWIW. |
To be perfectly clear--what are the rules for |
It's protected by TABLES_LOCK(). Basically, the whole tracemalloc state is protected by TABLES_LOCK(). The GIL is needed on memory allocations to get the traceback. It's not needed on deallocations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Merged. Thanks for your reviews @ZeroIntensity! |
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(), _PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check tracemalloc_config.tracing after calling TABLES_LOCK().
_PyTraceMalloc_TraceRef() now always returns 0.