python / python/cpython

Potential thread unsafety in test_free_threading.test_monitoring

Abierto
#135,633 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

tests topic-free-threading type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
36k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug report

Bug description:

It seems that there is some kind of race with test_free_threading.test_monitoring, specifically the sys.settrace tests:
https://github.com/python/cpython/blob/fba5dded6df3c2b1943557afef89a5cb418f65a2/Lib/test/test_free_threading/test_monitoring.py#L143-L166.

This was initially spotted in a buildbot failure here: https://buildbot.python.org/#/builders/1610/builds/1590. There have been a few behaviors noted:

  • refleaks causing a test failure
  • assertion failures
  • presumed deadlocks or other contention causing the tests to run extremely slowly (timing out after 45 minutes)
  • tests pass without issue 😬

The variety of failure modes makes me think there is some kind of thread safety issue lurking behind the failures...

After some local debugging (the remote debugger rocks!), I was able to reproduce the extremely long test run of test_freethreading, and narrow down the majority of the time being in the sys.settrace tests. My command line was:

./python -E  -m test --timeout=2700 -R 3:3 -u-cpu -j10 test_free_threading

On my x86 laptop on Ubuntu 24.04/WSL.

Reading over the test, it isn't clear to me what is meant to be tested. sys.settrace only affects the current thread according to the docs (indeed, the C code sets the trace function to the current threadstate), so currently it is only checking that the main thread executes a frame of some sort.

I didn't have time to find the root cause of the weird behavior above, so I'm filing this bug to note down my findings.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con las líneas 143-166 de Lib/test/test_free_threading/test_monitoring.py y reproduce el problema con ./python -E -m test --timeout=2700 -R 3:3 -u-cpu -j10 test_free_threading. Investiga las pruebas de sys.settrace junto con el fallo enlazado de buildbot y determina el origen de la condición de carrera, la contención o las fugas. Se considera terminado cuando se entiende el modo de fallo y las pruebas afectadas se ejecutan de forma fiable.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
testing-qa
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.