Skip to content
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

Unable to load large wasm modules when loading through wasi #302

Closed
HarukaMa opened this issue Feb 15, 2022 · 3 comments
Closed

Unable to load large wasm modules when loading through wasi #302

HarukaMa opened this issue Feb 15, 2022 · 3 comments
Assignees

Comments

@HarukaMa
Copy link

I'm using wasmer-js for a wasi environment to run a pretty large wasm module with some parts of openssl. However I'm unable to load the module through wasi.instantiate().

wasmer 2.0.0 | rustc 1.60.0-nightly (4e8fb743c 2022-02-03) | x86_64

Steps to reproduce

Currently I'm not able to provide a sample code, but trying to load a large enough wasm module on Chromium-based browser should trigger this.

Expected behavior

The module should load.

Actual behavior

There is a cryptic error in console:

Uncaught (in promise) Error: Failed to instantiate WASI: RuntimeError: `

Additional context

I've tried to modify the wasmer code to trace the error and found the error is from here:

https://github.com/wasmerio/wasmer/blob/2b396e0fad8118755184109ac5af770c937d66c0/lib/api/src/js/module.rs#L247-L251

The actual error caught here is:

RangeError: WebAssembly.Instance is disallowed on the main thread, if the buffer size is larger than 4KB. Use WebAssembly.instantiate.

I was not able to use any kind of block_on as std::thread::park panics in wasm.

Although I'm using wasmer-js, the actual code is in the wasmer repo so I reported the issue here.

@HarukaMa
Copy link
Author

HarukaMa commented Feb 19, 2022

I've rewritten wasi.instantiate to return a Promise and made Instance::new an async function and it now works in Chrome. Not sure if this change is desired though as it changes related functions to async and it seems nothing else is async function in wasmer repo. I'll not open a PR at this time.

This is what I've done:
HarukaMa/wasmer@55b71bd
HarukaMa@49f1dca

@corwin-of-amber
Copy link
Contributor

@syrusakbary This looks pretty critical to me since it renders the browser integration essentially unusable. Is there a workaround?

@syrusakbary
Copy link
Member

Since the release of wasmer-js v1.1.1 it's possible to construct the import object, and then instantiate manually (async):

  let wasi = new WASI({});
  const module = await WebAssembly.compile(moduleBytes);
  let importObject = wasi.getImports(module);
  let instance = await WebAssembly.instantiate(module, importObject);
  let exitCode = wasi.start(instance);
  let stdout = wasi.getStdoutString();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants