V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
yazoox
V2EX  ›  JavaScript

为什么我的 Jest 一跑就会挂掉,错误提示一会儿是 out of memory,一会儿是 EPIPE

  •  
  •   yazoox · 2020-07-17 23:49:42 +08:00 · 2945 次点击
    这是一个创建于 1618 天前的主题,其中的信息可能已经有所发展或是发生改变。

    windows 10 (1709)

    node 10.19.0

    Jest 26.0.1

    机器有 32g 内存。编译和运行都没有问题,就是 jest 无法正常跑完。

    这个是咋回事儿,没有头绪呢。

    在 macos 下跑 jest 就没有问题

    <--- Last few GCs --->
    
    [39960:0000015619EDC4D0]   127030 ms: Scavenge 25.7 (30.5) -> 24.9 (30.5) MB, 0.8 / 0.0 ms  (average mu = 0.998, current mu = 0.999) allocation failure
    [39960:0000015619EDC4D0]   129628 ms: Scavenge 25.8 (30.5) -> 24.9 (30.5) MB, 1.2 / 0.0 ms  (average mu = 0.998, current mu = 0.999) allocation failure
    [39960:0000015619EDC4D0]   131365 ms: Scavenge 25.8 (30.5) -> 24.9 (30.5) MB, 0.8 / 0.0 ms  (average mu = 0.998, current mu = 0.999) allocation failure
    
    
    <--- JS stacktrace --->
    
    ==== JS stack trace =========================================
    
        0: ExitFrame [pc: 00000230F2BDC87C]
        1: StubFrame [pc: 00000230F2C0FAB5]
    Security context: 0x00c35e29e6e9 <JSObject>
        2: initialize [0000011BDB729891] [C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildProcessWorker.js:145] [bytecode=000001792A6C2509 offset=111](this=0x034bdb811831 <ChildProcessWorker map = 0000005E90AC1AD1>)
        3: _onExit [0000011BDB729901] [C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildP...
    
    FATAL ERROR: Committing semi space failed. Allocation failed - JavaScript heap out of memory
     1: 00007FF7C169832A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
     2: 00007FF7C1672DB6 node::MakeCallback+4534
     3: 00007FF7C1673730 node_module_register+2032
     4: 00007FF7C198C14E v8::internal::FatalProcessOutOfMemory+846
     5: 00007FF7C198C07F v8::internal::FatalProcessOutOfMemory+639
     6: 00007FF7C1B72874 v8::internal::Heap::MaxHeapGrowingFactor+9620
     7: 00007FF7C1B6986C v8::internal::ScavengeJob::operator=+24572
     8: 00007FF7C1B67EAC v8::internal::ScavengeJob::operator=+17980
     9: 00007FF7C1B70BF7 v8::internal::Heap::MaxHeapGrowingFactor+2327
    10: 00007FF7C1B70C76 v8::internal::Heap::MaxHeapGrowingFactor+2454
    11: 00007FF7C1C9AB9B v8::internal::Factory::AllocateRawWithImmortalMap+59
    12: 00007FF7C1C9D50D v8::internal::Factory::NewRawOneByteString+77
    13: 00007FF7C1C9CC5A v8::internal::Factory::NewStringFromTwoByte+154
    14: 00007FF7C19A7ED1 v8::String::NewFromTwoByte+385
    15: 00007FF7C15F3453 v8::internal::StackGuard::ArchiveSpacePerThread+24899
    16: 00007FF7C1D7FF98 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+584
    17: 00007FF7C1D81953 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+7171
    18: 00007FF7C1D821DA v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+9354
    19: 00007FF7C1D82471 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+10017
    20: 00007FF7C1D806B0 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+2400
    21: 00007FF7C1D81135 v8::internal::InterpreterDispatchDescriptor::InitializePlatformIndependent+5093
    22: 00007FF7C19E74E3 v8::internal::Object::ToInt32+12803
    23: 00007FF7C1C94CE3 v8::internal::wasm::WasmCodeManager::LookupCode+51395
    24: 00000230F2BDC87C
    error Command failed with exit code 134.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    

    或者

          throw er; // Unhandled 'error' event
          ^
    
    Error: write EPIPE
        at ChildProcess.target._send (internal/child_process.js:762:20)
        at ChildProcess.target.send (internal/child_process.js:634:19)
        at ChildProcessWorker.send (C:\src\web-2nd\node_modules\jest-worker\build\workers\ChildProcessWorker.js:291:17)
        at WorkerPool.send (C:\src\web-2nd\node_modules\jest-worker\build\WorkerPool.js:32:34)
        at Farm._process (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:129:10)
        at Farm._enqueue (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:152:10)
        at Farm._push (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:159:12)
        at Promise (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:90:14)
        at new Promise (<anonymous>)
        at Farm.doWork (C:\src\web-2nd\node_modules\jest-worker\build\Farm.js:56:12)
    Emitted 'error' event at:
        at process.nextTick (internal/child_process.js:766:39)
        at process._tickCallback (internal/process/next_tick.js:61:11)
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
    
    7 条回复    2020-07-18 12:17:52 +08:00
    WittBulter
        1
    WittBulter  
       2020-07-18 02:38:20 +08:00 via iPhone
    试一下 jest -w 1
    msg7086
        2
    msg7086  
       2020-07-18 03:19:35 +08:00
    Let me Google that for you?

    https://stackoverflow.com/q/38558989/2221631 看看能不能解决。
    seki
        3
    seki  
       2020-07-18 04:54:08 +08:00
    换个 node 大版本
    看看 Jest 周边的一些库是不是没有升到新版本
    改变一下测试的数量,从 1 个开始
    改变一下并行 worker 的数量
    在 wsl 底下跑

    都试试看
    jiangzhuo
        4
    jiangzhuo  
       2020-07-18 09:39:22 +08:00
    都 32G 了就给进程多分点内存呗。
    yazoox
        5
    yazoox  
    OP
       2020-07-18 11:52:20 +08:00
    @jiangzhuo #4 这个…… 怎么指定 /分配?
    yazoox
        6
    yazoox  
    OP
       2020-07-18 11:54:19 +08:00
    @seki #3 只跑一个 test,或者一个 suite 都没问题。
    知道统一跑,就不行了。

    另,怎么设定 worker 等参数?
    jiangzhuo
        7
    jiangzhuo  
       2020-07-18 12:17:52 +08:00
    @yazoox #5 node --v8-options 里有写
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2477 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 05:09 · PVG 13:09 · LAX 21:09 · JFK 00:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.