wasm 代码提交分配失败 - 进程内存不足
Posted
技术标签:
【中文标题】wasm 代码提交分配失败 - 进程内存不足【英文标题】:wasm code commit Allocation failed - process out of memory 【发布时间】:2021-04-27 13:52:18 【问题描述】:我有一个 nodejs 脚本,它在 nodejs 12 上运行良好。我有一个新的 macbook air,我在上面安装了 nodejs LTS 14。脚本没有按预期工作,所以我已将其降级为 nodejs 12 LTS。现在我收到进程内存不足的错误。我也尝试过使用 --max-oud-size 来增加内存分配。
export NODE_OPTIONS=--max_old_space_size=4096
没有用。以下是错误的堆栈跟踪
<--- Last few GCs --->
[8193:0x150008000] 41 ms: Scavenge 2.9 (4.9) -> 2.7 (5.7) MB, 0.5 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[8193:0x150008000] 54 ms: Scavenge 3.9 (5.9) -> 3.6 (8.6) MB, 0.3 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[8193:0x150008000] 59 ms: Scavenge 5.2 (8.6) -> 3.9 (9.1) MB, 0.2 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x00010b1808d1 <JSObject>
0: builtin exit frame: new constructor(aka Module)(this=0x000102ea1961 <Object map = 0x10b3ecbc9>,0x000102ea1811 <Uint8Array map = 0x102fc2b99>,0x000102ea1961 <Object map = 0x10b3ecbc9>)
1: ConstructFrame [pc: 0x100ca8758]
2: StubFrame [pc: 0x100d91204]
3: /* anonymous */ [0x102ea10b1] [/Applications/XAMPP/xamppfiles/htdocs/web-dev/local-cron-jobs/node_modules/long/src/long.js:9...
FATAL ERROR: wasm code commit Allocation failed - process out of memory
1: 0x1004db324 node::Abort() [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
2: 0x1004db4a4 node::errors::TryCatchScope::~TryCatchScope() [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
3: 0x1005fab78 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
4: 0x1005fab0c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
5: 0x100b332bc v8::internal::wasm::WasmCodeAllocator::AllocateForCodeInRegion(v8::internal::wasm::NativeModule*, unsigned long, v8::base::AddressRegion) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
6: 0x100b34198 v8::internal::wasm::NativeModule::CreateEmptyJumpTableInRegion(unsigned int, v8::base::AddressRegion) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
7: 0x100b33660 v8::internal::wasm::NativeModule::AddCodeSpace(v8::base::AddressRegion) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
8: 0x100b33fd4 v8::internal::wasm::NativeModule::NativeModule(v8::internal::wasm::WasmEngine*, v8::internal::wasm::WasmFeatures const&, bool, v8::internal::VirtualMemory, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, std::__1::shared_ptr<v8::internal::Counters>, std::__1::shared_ptr<v8::internal::wasm::NativeModule>*) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
9: 0x100b36214 v8::internal::wasm::WasmCodeManager::NewNativeModule(v8::internal::wasm::WasmEngine*, v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
10: 0x100b3cb1c v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, unsigned long, bool, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
11: 0x100b3ca64 v8::internal::wasm::WasmEngine::NewNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
12: 0x100b14578 v8::internal::wasm::CompileToNativeModule(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, v8::internal::wasm::ErrorThrower*, std::__1::shared_ptr<v8::internal::wasm::WasmModule const>, v8::internal::wasm::ModuleWireBytes const&, v8::internal::Handle<v8::internal::FixedArray>*) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
13: 0x100b3a710 v8::internal::wasm::WasmEngine::SyncCompile(v8::internal::Isolate*, v8::internal::wasm::WasmFeatures const&, v8::internal::wasm::ErrorThrower*, v8::internal::wasm::ModuleWireBytes const&) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
14: 0x100b5bc98 v8::(anonymous namespace)::WebAssemblyModule(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
15: 0x10065f150 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
16: 0x10065e4b8 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<true>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
17: 0x10065dfb4 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
18: 0x100d2b0cc Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
19: 0x100ca8758 Builtins_JSBuiltinsConstructStub [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
20: 0x100d91204 Builtins_ConstructHandler [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
21: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
22: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
23: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
24: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
25: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
26: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
27: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
28: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
29: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
30: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
31: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
32: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
33: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
34: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
35: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
36: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
37: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
38: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
39: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
40: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
41: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
42: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
43: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
44: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
45: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
46: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
47: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
48: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
49: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
50: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
51: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
52: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
53: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
54: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
55: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
56: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
57: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
58: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
59: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
60: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
61: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
62: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
63: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
64: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
65: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
66: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
67: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
68: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
69: 0x100cad520 Builtins_InterpreterEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
70: 0x100caa5a8 Builtins_JSEntryTrampoline [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
71: 0x100caa24c Builtins_JSEntry [/Users/rahulbharati/.nvm/versions/node/v12.20.1/bin/node]
72: 0x150008000 ```
Any help appreciated. Thanks.
【问题讨论】:
【参考方案1】:此问题已在Node 15.3.0 中修复。
我更新了我的,对我来说效果很好。
【讨论】:
它对我不起作用。我已经完全卸载了 nodejs 并通过 homebrew 安装了 nodejs12 它工作了 这只是一个解决方案,如果您可以升级到 v15,但由于 14 是 LTS 版本,可能人们仍然需要那个。 如果您在 M1 上,您可能需要升级到节点 16。 不幸的是,升级节点并不总是一种选择。幸运的是,对于那些无法升级的人来说,有一个解决方法:***.com/a/67813764/4826740【参考方案2】:在 M1 上使用从 Github 安装的 NVM。
正在运行 v14.x
nvm 安装 15.3
编译大约需要 10 分钟。
现在工作。
【讨论】:
这对我有用,谢谢。不要忘记通过输入“nvm use 15.3”切换到新的节点版本【参考方案3】:目前,除了 node@15 之外,M1 macOS 上的 node 不能正常工作。 如果你使用的是基于arm64架构的node@12,在https://github.com/dcodeIO/long.js.git等一些脚本上可能会崩溃
如果你在 long.js 存储库中运行测试用例,你可以检查它。
如果您想知道您的节点是在哪个节点上构建的,请按照以下步骤操作:
$ node
Welcome to Node.js v12.21.0.
Type ".help" for more information.
>
> process.arch
'arm64'
上面的例子意味着节点二进制文件是为 arm64 架构(Apple Silicon M1 芯片)构建的。如果 node 在rosetta2 上运行,它将显示'x64'。
我在 long.js 和 node.js 源代码库中测试了一些测试用例。
arm64 的 Node@15:没问题 arm64 的 Node@12:long.js 和 node.js 测试用例中的一些错误 Node@12 for x64:没问题据我所知,arm64 的 node@12 对某些脚本运行良好,但某些脚本已经崩溃,例如 long.js。
编辑
2021 年 6 月 21 日,Homebrew 上的 node@14 已通过针对 arm64 的 long.js 测试用例。 (v14.17.1) 当然,node@16也支持。
但是,node@12 仍然有错误。 (v12.22.1)
【讨论】:
谢谢我搞砸了所有类型的东西 我发现 NVM 文档的 M1 部分对于克服这个问题也很有用:github.com/nvm-sh/nvm#install--update-script【参考方案4】:这个代码块能够让我克服这个令人沮丧的错误:
$ nvm uninstall 14
$ arch -x86_64 zsh
$ nvm install 14
$ nvm alias default 14
考虑将上面的 14
替换为您尝试运行的任何节点版本。
安装完成后,你可以运行node
后跟process.arch
来确认节点是在x64模式下运行的:
$ node
> process.arch
'x64'
然后,您需要从项目文件夹 (rm -rf node_modules
) 中删除节点模块并再次运行 npm i
。
【讨论】:
对我来说最简单的解决方案?。请注意,您仍然可以使用自己喜欢的外壳。示例:$ arch -x86_64 bash
这样做后我遇到了发热问题
为我的 M1 macbook air 工作。谢谢。
该死的,我在墙上撞了好几个小时。你救了我的命。【参考方案5】:
我在使用 node version v14 时遇到了这个错误。
为了解决这个问题,我安装了 NVM(节点版本管理器)。在此帮助下,我能够安装最新版本的节点,即 v15。 安装最新版本后,我没有收到任何错误。此外,使用节点版本管理器(NVM),如果某个项目需要,可以轻松更改节点的版本。这有时真的很有帮助。
祝你好运!
【讨论】:
【参考方案6】:我能够通过在编译节点时将此 pull request 的更改应用为补丁来修复 v14.16.0 的崩溃。
为了简化这一点,我创建了一个gist with the patch。
使用 node-build / nodeenv
安装命令:
curl -LO https://gist.githubusercontent.com/koenpunt/812953470f26b100845e2b37e1288067/raw/667daea235ac99236adb2dfa1499401358d004dd/node-14.16.0.patch
node-build -p 14.16.0 $(nodenv root)/versions/14.16.0 < node-14.16.0.patch
不使用nodenv
时,应将$(nodenv root)/versions/14.16.0
替换为要安装节点的路径。
没有节点构建
当不使用 node-build 时,您应该能够使用 git-apply 自己将补丁应用到源代码:
git apply node-14.16.0.patch
或者使用补丁命令:
patch -p1 < node-14.16.0.patch
【讨论】:
【参考方案7】:无法升级节点并需要一个快速的两分钟解决方案?
对于使用 M1 计算机并遇到此问题并且无论出于何种原因无法升级其节点版本的任何人,仍然有一个快速简便的解决方法:
-
转到终端所在的
Application/Utilities
文件夹。 (找到它的简单方法是右键单击终端图标,然后单击“在查找器中打开”。)这是一个屏幕截图:
右键单击终端并单击“复制”,然后将新终端重命名为“Rosetta-Terminal”。 (上图左下角)
右键单击Rosetta-Terminal --> “获取信息”--> 选择“使用 Rosetta 打开”。
现在打开 Rosetta-Terminal 并使用 nvm
输入 nvm uninstall YOUR.VERSION.HERE
。 (注意:它可能会说它无法安装它,因为您正在使用它,在这种情况下,只需临时安装任何其他版本并使用它。)如果您没有nvm
,那么您可以安装它here或运行:curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
。
nvm install YOUR.VERSION.HERE
Boom,现在您的节点已安装在Rosetta 下,它应该可以正常工作而无需升级您的节点版本。
Rosetta 是 Apple 允许为英特尔芯片构建的应用程序与 Apple Silicon 配合使用的一种方式。
正如其他答案所暗示的那样,升级您的节点版本并不总是那么容易。例如,您可能有其他需要特定节点版本的依赖项,升级这些依赖项将需要对您的应用进行重大提升和转变——幸运的是,我们有 Rosetta。
【讨论】:
有什么办法可以让这个新终端(而不是我的另一个)总是以红色打开? @WilliamEntriken 遗憾的是,我不完全确定你是如何做到这一点的,我假设某处有一个配置设置可以强制将这个设置为另一个 这对我有用。我只需要运行 Rosetta-Terminal 一次,就可以得到正确的 arm64 节点,安装需要几秒钟。之后,我又回到了默认终端。以上是关于wasm 代码提交分配失败 - 进程内存不足的主要内容,如果未能解决你的问题,请参考以下文章
RangeError:WebAssembly.Instance():内存不足:wasm 内存
编译为 Wasm 时,指向堆分配内存的 Rust 指针可以为 0 吗?