[BUG]: `type_info` data races in free threaded Python

Abierto
#5,421 0 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
cpp, python

Línea de trabajo

Comienza con detail::type_info y los campos alrededor de include/pybind11/pybind11.h en las líneas 1396-1412; después revisa el caso de prueba y la corrección propuesta en el pull request #5419. Rastrea las escrituras en registered_types_cpp, registered_types_py, implicit_casts, simple_type y en los campos de conversión y buffer bajo free-threaded Python. Se considera terminado cuando se hayan resuelto las data races notificadas y el caso de prueba del PR pase.

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

Descripción

triage
Required prerequisites
What version (or hash if on master) of pybind11 are you using?

master

Problem description

There are a few related data races in free threaded Python (3.13t) involving detail::type_info.

The most serious (found by @vfdev-5) is that the std::vector<type_info *> in registered_types_py is populated outside the internals lock, so a thread may incorrectly see an empty vector (or other crashes). Victor has a PR that addresses this race (#5419).

The other data races are because some fields in type_info may be modified after creation:

  • type_info::implicit_casts: vector is modified when subclasses are defined
  • type_info::simple_type: field is set to false when a subclass that uses multiple inheritance is defined

Additionally, a few fields are written after the type_info is exposed in registered_types_cpp/registered_types_py -- I think we want to reorder it so that those fields are initialized earlier.

Finally, there are a few fields that I think are mostly okay in typical usage, but I'm not entirely sure:

  • type_info::implicit_conversions: modified for py::implicitly_convertible<A, B>() on B's type_info.
  • type_info::direct_conversions: pointed-to vector modified by PYBIND11_NUMPY_DTYPE(type, ...)
  • type_info::get_buffer/get_buffer_data: modified by def_buffer()

I think these are okay because they're typically invoked when the type is bound, before the type_info is used by other threads.

Reproducible example code
See test case in https://github.com/pybind/pybind11/pull/5419
Is this a regression? Put the last known working version here if it is.

Not a regression

Lenguaje dominante
C++
Estrellas
18k
Forks
2.3k
Merge medio
5 d 7 h
PR fusionados (30 d)
53

Preparar el entorno

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.

Más de pybind/pybind11

Todos los issues de pybind/pybind11

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.