Free threading: Data race on `tool_id` in `sys.monitoring`
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:
Thanks devdanzin for his fusil, this issue was reported by #153852 TSAN-0030. It;s a data race about interp->monitoring_tool_names[tool_id]
how to reproduce
run the following on a no-gil tsan build
import sys, threading
assert not sys._is_gil_enabled(), "run free-threaded: PYTHON_GIL=0"
# sys.monitoring.use_tool_id(tool_id, name) does an unsynchronized check-then-act on the
# interpreter-global registry interp->monitoring_tool_names[tool_id]:
# if (interp->monitoring_tool_names[tool_id] != NULL) { raise; } # :2190 read
# interp->monitoring_tool_names[tool_id] = Py_NewRef(name); # :2194 write
# Many threads racing to claim the SAME free tool id read the slot while one writes it.
mon = sys.monitoring
TOOL_ID = 3 # any 0..5; not reserved
NT = 8
ROUNDS = 6000
enter = threading.Barrier(NT + 1)
leave = threading.Barrier(NT + 1)
def worker():
for _ in range(ROUNDS):
enter.wait() # all workers released together onto a freshly-freed slot
try:
mon.use_tool_id(TOOL_ID, "t") # read :2190 races the winner's write :2194
except ValueError:
pass # "tool 3 is already in use" -> lost the race, expected
leave.wait()
ts = [threading.Thread(target=worker, name=f"w{i}") for i in range(NT)]
for t in ts:
t.start()
for r in range(ROUNDS):
mon.free_tool_id(TOOL_ID) # NULL the slot so the next round starts from a free id
enter.wait()
leave.wait()
for t in ts:
t.join()
print("done, no crash")
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-154459
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 los puntos de entrada sys.monitoring.use_tool_id() y free_tool_id() referenciados alrededor de las líneas 2190 y 2194, y luego ejecuta el reproducer proporcionado en una compilación TSAN de no-GIL. Se considera terminado cuando la prueba repetida de claim/free concurrentes ya no informa de una data race y conserva el comportamiento esperado del tool-id; el PR enlazado gh-154459 indica que el trabajo ya está en curso.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 25/100