Skip to content

[3.13] gh-127582: Make object resurrection thread-safe for free threading. (GH-127612) #127659

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

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Dec 5, 2024

Objects may be temporarily "resurrected" in destructors when calling finalizers or watcher callbacks. We previously undid the resurrection by decrementing the reference count using Py_SET_REFCNT. This was not thread-safe because other threads might be accessing the object (modifying its reference count) if it was exposed by the finalizer, watcher callback, or temporarily accessed by a racy dictionary or list access.

This adds internal-only thread-safe functions for temporary object resurrection during destructors.
(cherry picked from commit f4f5308)

… threading. (pythonGH-127612)

Objects may be temporarily "resurrected" in destructors when calling
finalizers or watcher callbacks. We previously undid the resurrection
by decrementing the reference count using `Py_SET_REFCNT`. This was not
thread-safe because other threads might be accessing the object
(modifying its reference count) if it was exposed by the finalizer,
watcher callback, or temporarily accessed by a racy dictionary or list
access.

This adds internal-only thread-safe functions for temporary object
resurrection during destructors.
(cherry picked from commit f4f5308)

Co-authored-by: Sam Gross <[email protected]>
@colesbury colesbury merged commit 69bb1c6 into python:3.13 Dec 5, 2024
39 checks passed
@colesbury colesbury deleted the backport-f4f5308-3.13 branch December 5, 2024 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant