zeromq / pyzmq

PyZMQ: Python bindings for zeromq
http://zguide.zeromq.org/py:all
BSD 3-Clause "New" or "Revised" License
3.66k stars 638 forks source link

BUG: pyzmq-included msvcp140.dll on Windows will break other packages #2012

Closed jackjansen closed 3 weeks ago

jackjansen commented 1 month ago

This is a pyzmq bug

What pyzmq version?

26.1.0

What libzmq version?

not relevant

Python version (and how it was installed)

3.11.8 (but not really relevant)

OS

Win10

What happened?

pyzmq-installed msvcp140.dll is loaded once zmq is imported. This breaks any package linked against a newer MSVC C++ runtime.

Code to reproduce bug

First import zmq (which loads the included VC++ runtime DLL).
Next import any Python package that is linked against VC++ runtime 14.40.44810 or newer.
See how that Python package crashes, usually on the DLL initialiser machine, while it is trying to access a mutex.

Traceback, if applicable

No response

More info

Microsoft guarantee that their VC++ runtimes (the "MSVC Redist" packages) are backward compatible, but explicitly not forward compatible.

In 14.40.44810, released around May 2024, they have made a backward incompatible change (something to do with the initialisation of mutexes).

The effect of this is that anything that has been built against the current VC++ runtime will crash if at execution time it gets an older version of msvcp140. And if pyzmq is loaded first into the Python interpreter it will load its old copy of msvcp140, which causes later loaded module to use that copy (in stead of loading the correct copy from /Windows/system32/msvcp140.dll.

Microsoft used to suggest that everyone include VC++ redist in their installers, and while they don't do so any more I'm rather surprised that they don't warn against it. Because the problem not only happens with Python modules (as in this case) but also with any program that includes msvcp140 in a directory that gets prepended to %PATH%...

minrk commented 4 weeks ago

I think we may need to copy https://github.com/matplotlib/matplotlib/pull/28687

tacaswell commented 4 weeks ago

xref to mpl issue: https://github.com/matplotlib/matplotlib/issues/28551

minrk commented 4 weeks ago

2015 should do the same thing matplotlib is doing. I don't fully understand the consequences or how to test what might be broken or fixed by this.