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

Potential Wasm execution limits in some low-memory environments #40201

Closed
guybedford opened this issue Sep 24, 2021 · 19 comments
Closed

Potential Wasm execution limits in some low-memory environments #40201

guybedford opened this issue Sep 24, 2021 · 19 comments
Labels
wasm Issues and PRs related to WebAssembly.

Comments

@guybedford
Copy link
Contributor

Version

12

Platform

?

Subsystem

No response

What steps will reproduce the bug?

I'm getting a few reports in nodejs/cjs-module-lexer#61 (comment) that cpanel environments running Node.js 12 may be hitting a Wasm out of memory issue in the Wasm allocation requirements for the lexer.

It is worth keeping an eye on these issues from a reliability perspective.

Note this path is only hit when importing CommonJS from an ES module for the first time as well, so it won't be soon on all boots but only as users adopt ES modules.

How often does it reproduce? Is there a required condition?

It seems to be very low memory environments.

What is the expected behavior?

No response

What do you see instead?

WebAssembly.instantiate throwing an out of memory error.

Additional information

No response

@guybedford
Copy link
Contributor Author

Note this is not lexer specific - it is simply being unable to intialize the Web Assembly module at all. The only requirement on Wasm memory in the lexer is a 13KB stack size requirement.

@targos
Copy link
Member

targos commented Sep 24, 2021

Any idea about how low the memory needs to be? I'd like to try to reproduce with Docker.

@guybedford
Copy link
Contributor Author

That would be great to try. I was able to get them to give a report in nodejs/cjs-module-lexer#61 (comment).

@guybedford
Copy link
Contributor Author

The stackoverflow listing for this is also getting traffic - https://stackoverflow.com/questions/68991747/rangeerror-webassembly-instantiate-out-of-memory-wasm-memory.

@targos
Copy link
Member

targos commented Sep 24, 2021

I'm unable to reproduce with Docker.

Tried with docker run --memory=6m image node app.mjs (the minimum that Docker allows).

My test case is:

// app.mjs
import { value } from './module.cjs';
console.log(value);
// module.cjs
exports.value = 42;

Edit: I used the latest node:12official image.

@guybedford
Copy link
Contributor Author

It seems to be some kind of interaction specifically in these types of virtual hosting environments. Perhaps a v8 bug?

@guybedford
Copy link
Contributor Author

Thanks so much for verifying the memory case, that's great to know! cjs-module-lexer reuses its heap for all analyses since they are sync so cleaned on each run it's just the Wasm instantiation specifically to worry about here.

@Mesteery Mesteery added the wasm Issues and PRs related to WebAssembly. label Sep 24, 2021
@addaleax
Copy link
Member

Last I checked, for WASM it's particularly relevant to look at the virtual memory size limit, not (just) the actual RSS limit (which is what most people would refer to as "the memory limit"), because V8 reserves (but not actually allocated) large ranges of memory for WASM.

@guybedford
Copy link
Contributor Author

@addaleax thanks for the info, what debugging commands would you suggest I ask for while this replication is still current?

@addaleax
Copy link
Member

@guybedford I’m not sure, but you can check the virtual memory limit/set it through ulimit -v.

@guybedford
Copy link
Contributor Author

Seems this Twitter thread is closely related - https://twitter.com/_rvidal/status/1442868528068108289?s=20.

@guybedford
Copy link
Contributor Author

And Chromium issue - https://bugs.chromium.org/p/v8/issues/detail?id=12076

@guybedford
Copy link
Contributor Author

Another case - sveltejs/kit#2551.

If this turns out to be a bigger problem, I recently compiled es-module-lexer to asm.js with similar performance. We could make a special Node.js patch for 12 with asm.js instead of Wasm to avoid the issue. It would be a little bit of a process but could be an option if this is deemed worth the effort. Let's keep an eye on it...

@sianlasaga
Copy link

sianlasaga commented Dec 10, 2021

Not sure if this can help but I was able to reproduce this with docker (by setting ulimit -v <n> before running). I noticed the issue appeared starting in Node v12.22.0. I didn't encounter the said problem in Node v12.21.0 and below.

@asheroto
Copy link

asheroto commented Feb 21, 2022

I'm having this issue as well.

@richardlau
Copy link
Member

@guybedford Did this affect any later Node.js release lines than 12? Node.js 12 is now End-of-Life and won't be getting further updates.

@guybedford guybedford changed the title Node.js 12 potential Wasm execution limits in some low-memory environments Potential Wasm execution limits in some low-memory environments May 5, 2022
@guybedford
Copy link
Contributor Author

@richardlau there was actually a Node.js 14 report in nodejs/cjs-module-lexer#61 (comment), so it may be worth keeping this open.

@mmgoodnow
Copy link

seems this has been fixed as of v18.6.0 - #43612

@pandyama
Copy link

@mmgoodnow thanks! tried it out and it didnt crash

rayriffy added a commit to rayriffy/rayriffy-h that referenced this issue Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasm Issues and PRs related to WebAssembly.
Projects
None yet
Development

No branches or pull requests

9 participants