Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash from concurrent nb::make_iterator<> under free-threading. #832

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hawkinsp
Copy link
Contributor

@hawkinsp hawkinsp commented Dec 23, 2024

The State class used by make_iterator is constructed lazily, but without locking it is possible for the caller to crash when the class type is only partially constructed. This PR adds an ft_mutex around the binding of the State type.

My initial instinct was to use an nb_object_guard on scope. Unfortunately this doesn't work; I suspect PyEval_SaveThread() is called during class binding and that releases the outer critical section.

@hawkinsp hawkinsp changed the title Fix crash from concurrent when nb::make_iterator<> under free-threading. Fix crash from concurrent nb::make_iterator<> under free-threading. Dec 23, 2024
The `State` class used by make_iterator is constructed lazily, but
without locking it is possible for the caller to crash when the class
type is only partially constructed. This PR adds an ft_mutex around the
binding of the State type.

My initial instinct was to use an nb_object_guard on `scope`.
Unfortunately this doesn't work; I suspect PyEval_SaveThread() is called
during class binding and that releases the outer critical section.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant