[Free-threading] `assert(!_Py_IsImmortal(op))` failure when BRC merge queue races with `sys.intern`
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
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:
assert.h assertion failed at Objects/object.c:467 in Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *, Py_ssize_t): !_Py_IsImmortal(op)
*** Check failure stack trace: ***
@ _Py_ExplicitMergeRefcount
@ merge_queued_objects
@ _Py_brc_merge_refcounts
@ _Py_HandlePending
@ _PyEval_EvalFrameDefault
Reproduction. Fails when running under ASAN/TSAN and the free-threading build:
import threading
import sys
def test_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) for j in range(1000000)]
# Give Thread B a copy of the list.
shared = list(strings)
def thread_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()
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-152277
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con Objects/object.c en _Py_ExplicitMergeRefcount y rastrea la ruta de llamadas mencionada de merge_queued_objects, _Py_brc_merge_refcounts y _Py_HandlePending. Reproduce la condición de carrera con ASAN o TSAN usando la compilación free-threaded y luego compara el comportamiento y la resolución en el PR enlazado gh-152277.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 30/100