Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

在pipeline跑UT时遇到了JavaScript堆内存不足的问题。

一、问题描述

项目为angular工程,CICD均在gitlab pipeline进行。在跑UT时出现如下报错。

20 04 2021 09:31:12.770:INFO [karma-server]: Karma v5.2.3 server started at http://localhost:9876/
20 04 2021 09:31:12.773:INFO [launcher]: Launching browsers ChromeHeadlessCI with concurrency unlimited
20 04 2021 09:31:12.791:INFO [launcher]: Starting browser ChromeHeadless
20 04 2021 09:32:12.827:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing.
20 04 2021 09:32:18.178:INFO [launcher]: Trying to start ChromeHeadless again (1/2).
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
<--- Last few GCs --->
[40:0x3f5ad80]   127426 ms: Mark-sweep 1367.8 (1447.5) -> 1357.9 (1449.5) MB, 507.1 / 0.0 ms  (average mu = 0.171, current mu = 0.101) allocation failure scavenge might not succeed
[40:0x3f5ad80]   128003 ms: Mark-sweep 1369.3 (1449.5) -> 1361.1 (1453.0) MB, 545.6 / 0.0 ms  (average mu = 0.113, current mu = 0.054) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
    0: ExitFrame [pc: 0x13c2416dbe1d]
    1: StubFrame [pc: 0x13c2416d2d85]
Security context: 0x3abe3409e6e9 <JSObject>
    2: split [0x3abe340906c9](this=0x3c6c672378d9 <String[128]: /builds/mindsphere-ali/platform/starterservices/webcomponents/core-ali/node_modules/echarts/lib/component/tooltip/TooltipView.js>,0x2aba6243ab99 <JSRegExp <String[3]: \/+>>)
    3: /* anonymous */ [0x2aba624205e9] [/builds/mindsphere-ali/platform/starterserv...
 1: 0x8fa050 node::Abort() [ng test --configuration=test --watch=false --code-coverage]
 2: 0x8fa09c  [ng test --configuration=test --watch=false --code-coverage]
 3: 0xb0020e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng test --configuration=test --watch=false --code-coverage]
 4: 0xb00444 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng test --configuration=test --watch=false --code-coverage]
 5: 0xef4952  [ng test --configuration=test --watch=false --code-coverage]
 6: 0xef4a58 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [ng test --configuration=test --watch=false --code-coverage]
 7: 0xf00b32 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [ng test --configuration=test --watch=false --code-coverage]
 8: 0xf01464 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng test --configuration=test --watch=false --code-coverage]
 9: 0xf040d1 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [ng test --configuration=test --watch=false --code-coverage]
10: 0xecd554 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [ng test --configuration=test --watch=false --code-coverage]
11: 0x116d6de v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [ng test --configuration=test --watch=false --code-coverage]
12: 0x13c2416dbe1d 
Aborted (core dumped)
npm ERR! Test failed.  See above for more details.
二、解决方案

看了几篇博客,都尝试了下,亲测有两种方案是有效的。

方案一:

在package.json里面:加上这一句:–max_old_space_size=8192// 或 --max_old_space_size=4096(建议先设置成4G看看,如果不行在设置为8G)

"scripts": {
   "test": "ng test"
},

修改为

"scripts": {
   "test": "node --max_old_space_size=8192 ./node_modules/.bin/ng test"
},

--max_old_space_size这个参数是针对node的,不能直接ng --max_old_space_size test

方案二:

设置NODE_OPTIONS

- export NODE_OPTIONS=--max_old_space_size=4096
- npm test
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值