Skip to content

BUG: Prevent deadlock due to downstream importing NumPy in dlopen (#31303)#31335

Merged
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
charris:backport-31303
Apr 26, 2026
Merged

BUG: Prevent deadlock due to downstream importing NumPy in dlopen (#31303)#31335
charris merged 1 commit into
numpy:maintenance/2.4.xfrom
charris:backport-31303

Conversation

@charris
Copy link
Copy Markdown
Member

@charris charris commented Apr 26, 2026

Backport of #31303.

Downstream should probably never import numpy (i.e. activate the C-API) during dlopen (rather than the Python module init function).

But if it does so, this check introduced a deadlock regression because dlopen has a recursive lock, but this breaks if the matmul is called and causes threads to spawn that also need to dlopen.

So, as a hot-fix, just only run the check on MacOS, since we are not currently aware of reports on other system (possible or not), although this did happen with certain OpenBLAS versions (and not just accelerate).

(I cannot fully rule out that there won't be regressions on some linux setups, but they were not yet reported. -- The "limit to 1 thread" solution is an alternative as well.)

EDIT: addresses gh-31284. Should be backported for 2.4.5

…mpy#31303)

Downstream should probably never import numpy (i.e. activate the C-API) during dlopen (rather than the Python module init function).

But if it does so, this check introduced a deadlock regression because dlopen has a recursive lock, but this breaks if the matmul is called and causes threads to spawn that also need to dlopen.

So, as a hot-fix, just only run the check on MacOS, since we are not currently aware of reports on other system (possible or not), although this did happen with certain OpenBLAS versions (and not just accelerate).

(I cannot fully rule out that there won't be regressions on some linux setups, but they were not yet reported. -- The "limit to 1 thread" solution is an alternative as well.)
@charris charris added this to the 2.4.5 release milestone Apr 26, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Apr 26, 2026
@charris charris merged commit 24f329e into numpy:maintenance/2.4.x Apr 26, 2026
74 of 77 checks passed
@charris
Copy link
Copy Markdown
Member Author

charris commented Apr 26, 2026

Test failures are unrelated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants