-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Crash in macOS when using wasmtime in a Python extension #10099
Comments
I added the |
The crash happens when
Do you happen to know the exact set of entitlements this executable was compiled with? Maybe one of the hardening entitlements prevents using exception ports? |
The Python interpreter executable doesn't seem to specify any entitlement:
|
With this other path I get a different result, but nothing that prevents the use of exception ports.
|
Thanks for the thorough report and reproduction steps! I took a look at this but alas don't have much to add. It deifnitely seems like macOS doesn't like the call to |
To make this issue even more strange, everything is OK with a Python binary downloaded from python.org. Exactly the same version (Python 3.9.6), it crashes with the Python binary provided by Apple, but works correctly with the one from python.org. It looks like Apple is making some modifications to the Python binary they distribute. |
This is a very esoteric issue related to the use of Mach ports for exception handling when
wasmtime
is running inside a Python 3.9 process. I'm the author of a multi-platform Rust library that embedswasmtime
for running WASM code, the library supports Linux, Windows and macOS. This library also have Python bindings that allow using the library from Python.A user of the library reported a crash that was happening in a very specific environment: macOS 15.2 (both Intel and ARM are affected, and probably other macOS versions too), with Python 3.9.6 (the version that comes pre-installed in macOS). The process was being SIGKILLed when executing code deep inside
wasmtime
, the same code worked fine in other platforms, or in the same macOS machine with Python 3.11.After some investigation everything pointed to the Mach ports exception handling mechanism when
wasmtime
is run inside Python 3.9. In fact, if I turn off the use of Mach ports in wasmtime everything works fine.I don't have a clue on why this is happening only with Python 3.9. My guess is that it is related to Python's exception handling mechanism that somewhat is interfering with wasmtime's exception handling, and perhaps something changed in later Python versions. It could be a Python's bug that was fixed, it could a design change. For the time being I can turn off Mach ports as a workaround, but I would like to understand what's happening here.
wasmtime-python.zip
Test Case
As my library is a quite complicated project, I've created a simple Rust project that reproduces the issue (attached to this issue). It consists in a Python extension written in Rust using PyO3.
Steps to Reproduce
maturin build --release
/usr/bin/python3 -m pip install <path to the .whl file produced by maturin>
crash.py
file included in the project:/usr/bin/python3 crash.py
Expected Results
The process should finish without crashes.
Actual Results
The process gets killed:
The crash log is included below, notice that the exception type is
EXC_GUARD
and the code isGUARD_TYPE_MACH_PORT
. According to Apple's documentation, the process is killed withEXC_GUARD
when it detects a violation in some guarded resourced, usually a file descriptor or Mach port.Versions and Environment
Wasmtime version or commit: 29.0.1
Operating system: macOS 15.2
Architecture: both Intel and ARM
Extra Info
By disabling the use of Mach ports for exception handling (with macos_use_mach_ports) the problem disappears.
The text was updated successfully, but these errors were encountered: