Skip to content

gh-149816: Fix another variant of race on setattr/managed dict going … - #160278

Draft
DinoV wants to merge 1 commit into
python:mainfrom
DinoV:gh149816
Draft

DinoV wants to merge 1 commit into
python:mainfrom
DinoV:gh149816

Conversation

@DinoV

@DinoV DinoV commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

There's a couple of remaining issues with doing a setaddr. If we have a split dictionary we're not increfing the dictionary. Also, when we insert a split key it takes a lock which can cause the object/dict locks to be released so we need to guard against that.

The code here is pretty complex so it's also an attempt to simplify it. _PyObject_StoreInstanceAttribute loses any Py_GIL_DISABLEd ifdef's, instead we just have the main path with Py_BEGIN_CRITICAL_SECTION and FT_ATOMIC_LOAD_UINT8 and so on just turn into nothing when we're in the free threaded build. I've also just updated things to go directly to _PyDict_SetItem_LockHeld when we're doing the dictionary version and made store_instance_attr_lock_held only be used when we don't have a materialized dictionary. Going through the fast split dictionary case it dictinsert isn't substantially different but it really complicates reasoning about what's going on here and causes `store_instance_attr_lock_held to need to handle a lot more cases.

@bedevere-app bedevere-app Bot mentioned this pull request Oct 22, 2026
13 of 24 tasks
@DinoV
DinoV force-pushed the gh149816 branch 2 times, most recently from 2f8aa46 to 72a0e10 Compare October 22, 2026 23:17
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.

1 participant