Skip to content

gh-129185: Fix crash during interpreter finalization in PyTraceMalloc_Untrack #129188

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

Closed
wants to merge 1 commit into from

Conversation

rostan-t
Copy link

@rostan-t rostan-t commented Jan 22, 2025

This fixes the crash by moving _PyTraceMalloc_Fini() after _PyImport_Fini(). I'm not sure if it breaks some invariant that I'm not aware of or even if it's the best solution, happy to take feedbacks!

Signed-off-by: Rostan Tabet <rtabet@nvidia.com>
@ghost
Copy link

ghost commented Jan 22, 2025

The following commit authors need to sign the Contributor License Agreement:

Click the button to sign:
CLA not signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 22, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test?

@vstinner
Copy link
Member

I wrote a different fix with a test: PR gh-129191.

@rostan-t
Copy link
Author

Thanks @vstinner! Closing this one

@rostan-t rostan-t closed this Jan 22, 2025
/* Finalize any remaining import state */
// XXX Move these up to where finalize_modules() is currently.
_PyImport_FiniCore(tstate->interp);
_PyImport_Fini();

/* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */
_PyTraceMalloc_Fini();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this fix is enough. Some objects can be deleted later, in finalize_interp_clear(). So I wrote a different fix to restore the old behavior: PR gh-129191.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants