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

Uncaught RangeError: WebAssembly.Instance(): Out of memory: wasm memory #301

Open
KatarinaSimnova opened this issue Aug 5, 2022 · 4 comments

Comments

@KatarinaSimnova
Copy link

KatarinaSimnova commented Aug 5, 2022

Hi, when using function sodium.crypto_pwhash in webview on a mobile phone (tested on Samsung S21 and Pixel 3) we randomly get this error:
“Uncaught RangeError: WebAssembly.Instance(): Out of memory: wasm memory”

According to this article: https://blog.stackblitz.com/posts/debugging-v8-webassembly/ the only way to solve this is to optimize the code to not instantiate too many wasm modules. Do you think it would be possible to optimize the code in this library and fix the bug on mobile devices?

@jedisct1
Copy link
Owner

jedisct1 commented Aug 5, 2022

The pwhash function takes two parameters: the number of iterations, and how much memory to use.

If a runtime doesn't allow using enough memory to match the parameters used by your application, you can reduce the memory parameter, and bump the number of iterations up as a counterbalance.

@gutjuri
Copy link

gutjuri commented Feb 22, 2023

I have the same issue. However, I can't change the parameters to the function in question since it's part of a dependency I use. Would it be possible to address this bug in this library?

@jedisct1
Copy link
Owner

This is not a bug :)

If you're calling a function that requires reserving a lot of memory, but the browser doesn't allow reserving that much memory, there are no ways to work around this. Your application needs to use less memory.

@gutjuri
Copy link

gutjuri commented Mar 2, 2023

Well, doing require("libsodium-wrappers"); in my JS code (which I run in node.js) is enough to provoke the above-mentioned error, so I don't really think that this is an issue with my code.

It may be worth mentioning that I only get the error when I run the code in an Intel SGX enclave (that has a size >8GB), so it may be related to that. However, I can't really investigate this because the error gives no stack trace.

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