You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Free-threading] assert(!_Py_IsImmortal(op)) failure when BRC merge queue races with sys.intern #152276
In the free-threaded build, there is a race condition where an object can be queued for Biased Reference Counting (BRC) merging, but become immortal before the queue is processed. This causes a fatal C-level assertion failure:
Reproduction. Fails when running under ASAN/TSAN and the free-threading build:
importthreadingimportsysdeftest_race():
# 1 million strings will trap Thread A inside map() for milliseconds,# giving Thread B plenty of time to queue references to strings that # Thread A hasn't interned yet.strings= ["race_string_massive_"+str(j) forjinrange(1000000)]
# Give Thread B a copy of the list.shared=list(strings)
defthread_b_func():
# Thread B clears its list, reducing the shared refcount to 0.# Since Thread B is not the owner, they are placed in Thread A's merge queue.shared.clear()
tb=threading.Thread(target=thread_b_func)
tb.start()
# Thread A executes entirely in C for milliseconds.# Strings are queued by Thread B, AND THEN made immortal by sys.intern!list(map(sys.intern, strings))
tb.join()
if__name__=="__main__":
test_race()
Activity
gh-152276: Fix assertion failure when an object becomes immortal whil…
[3.15] gh-152276: Fix assertion failure when an object becomes immort…