-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
Problem description
It appears that, while the shared internals
are protected with a PyMutex
on free-threaded builds, the module-local local_internals
have no synchronization at all. Some accesses happen to be protected by the internals mutex, but that mutex does not seem to be held on calls to get_type_info(const std::type_index&)
, which calls get_local_type_info
, which does a direct lookup in registered_types_cpp
. If another thread is concurrently registering or unregistering a type, a crash would probably result in some scenarios, especially if the registered_types_cpp
map needs to be rehashed to accommodate the new insertion.
This is from reading the code, not from observing behavior, so it's possible I'm missing something. If I'm not, probably the easiest fix would be to wrap the local internals lookup in with_internals
so it's protected by the global mutex. Some refactoring might enable both the local and global lookups to occur under the same lock so that this change wouldn't regress performance.
Reproducible example code
Is this a regression? Put the last known working version here if it is.
Not a regression