kleisauke / wasm-vips

libvips for the browser and Node.js, compiled to WebAssembly with Emscripten.
https://kleisauke.github.io/wasm-vips/
MIT License
463 stars 25 forks source link

Mark all threadpool Workers as weakly referenced #29

Closed RReverser closed 1 year ago

RReverser commented 1 year ago

This is the workaround I mentioned in https://github.com/emscripten-core/emscripten/pull/18227. Since we know all the threads in the app are part of the threadpool, they can be just weakly referenced, so that the existence of the Worker alone doesn't prevent Node.js from exiting, and instead it's the blocking that waits for results of specific ops that keeps the event loop alive.

This allows to get rid of non-JS-esque shutdown helper.

atjn commented 1 year ago

FYI I am currently using a custom compiled version of wasm-vips, because if you call vips.shutdown() while running on a Netlify server, the entire Node process crashes without an error message. This does not happen on any other platform, and wasm-vips still runs perfectly fine on Netlify up until shutdown is called. I have solved this by compiling a version of wasm-vips that includes this commit: https://github.com/atjn/easy-web-app-builder/commit/173bc1cf6fd93482ca7a0305f2a03a46aa346135