wasmtime: macos: "failed to set thread exception port" in forked process

Hello,

Avid Wasmtime users in our Nginx embedding, we are facing an assertion failure when running it with Wasmtime on macos (x86 and arm64):

thread '<unnamed>' panicked at 'assertion failed: `(left == right)`
  left: `268435466`,
 right: `0`: failed to set thread exception port', crates/runtime/src/traphandlers/macos.rs:474:9

This assertion systematically fails with Wasmtime 8.0.1 (and probably earlier) to 11.0.1 when Nginx is configured with daemon on (which ends here in Nginx forking into a background process). It seems it occurs in our call to wasmtime_linker_instantiate after having initialized an engine and a single store.

Not forking the master process (daemon off) seems to be working fine, even in forked worker processes (managed by the master process in foreground); instances are created and behave as expected in the Nginx worker processes. The assertion failure specifically occurs once the master process has forked itself into a background process with daemon on.

In summary:

  • Works with daemon off: master process (foreground) -> wasmtime_linker_instantiate (temporary instance) -> fork() -> worker processes -> wasmtime_linker_instantiate (worker instances processing requests).
  • Fails with daemon on: master process (foreground) -> fork() (background daemon) -> wasmtime_linker_instantiate (temporary instance) -> assertion failure, no instance created, and no chance to fork() into worker processes.

In the past we used to have a CI/CD pipeline with macos targets and Wasmtime used to work fine; but this CI/CD pipeline was taken down, and this bit us in the last few days. It seems like older macos work on Wasmtime has something to do with it, but I know nothing of the macos system interface…

So far the root cause of this assertion failure has eluded us; probably state that aren’t being carried over to the forked process or something like this. Could someone shed some light on what may be at cause here?

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18 (17 by maintainers)

Commits related to this issue

Most upvoted comments

If you don’t want to modify the source --features wasmtime/posix-signals-on-macos may also work.

I think everything is now handled here with a combo of what I mentioned above:

I’m going to close this now but @thibaultcha if there’s anything else please comment here!

Yeah, it appears to be missing from the wasmtime-c-api crate, just needs to forward the feature to the wasmtime crate:

crates/c-api/Cargo.toml:

[features]
...
posix-signals-on-macos = ["wasmtime/posix-signals-on-macos"]