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

Process out of memory, on multiple jest versions #975

Closed
ColCh opened this issue May 6, 2016 · 9 comments
Closed

Process out of memory, on multiple jest versions #975

ColCh opened this issue May 6, 2016 · 9 comments

Comments

@ColCh
Copy link
Contributor

ColCh commented May 6, 2016

Our codebase is not that huge. Around 50 small modules.

This error pops up when running jest with or without coverage.

Testing all modules (command: just a jest)

<--- Last few GCs --->

   58239 ms: Scavenge 1400.2 (1452.1) -> 1400.2 (1452.1) MB, 5.7 / 0 ms (+ 3.9 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
   59209 ms: Mark-sweep 1400.2 (1452.1) -> 1400.2 (1452.1) MB, 969.6 / 0 ms (+ 64.8 ms in 493 steps since start of marking, biggest step 3.9 ms) [last resort gc].
   60164 ms: Mark-sweep 1400.2 (1452.1) -> 1400.2 (1452.1) MB, 955.0 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x2374abbe3ac1 <JS Object>
    1: ArraySlice [native array.js:~568] [pc=0x57ad9775260] (this=0x134cee9241f9 <an Arguments with map 0x3f792b70b169>,av=0x2374abb04189 <undefined>,aw=0x2374abb04189 <undefined>)
    2: arguments adaptor frame: 0->2
    6: /* anonymous */ [/foo-project/node_modules/jest-mock/src/index.js:203] [pc=0x57ad977202e] (this=0x2374abbfd081 <JS Global Object>)
...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

(JS stacktrace is null...)

I'm using node v5.10.1.
I tried jest@12, jest@11, jest@0.9

It runs well when executing files one by one, but running on all tests it blows up.

Node process consumes aroung 1G of mem.

@ColCh ColCh changed the title Process out of memory Process out of memory, on multiple jest versions May 6, 2016
@cpojer
Copy link
Member

cpojer commented May 6, 2016 via email

@ColCh
Copy link
Contributor Author

ColCh commented May 10, 2016

Thanks for your answer. Sory for delay.

OOM - with coverage collection and without it

At first step I will try to profile my code for myself. May be I have memory leak in my code? Or Images can consume a lot of memory?

@cpojer
Copy link
Member

cpojer commented May 10, 2016

I'm pretty sure you aren't loading any images in Jest, are you? :)

While Jest could be better with memory use, it is very likely that your tests are for some reasons not being torn down properly and retaining module code that are being required.

@ColCh
Copy link
Contributor Author

ColCh commented May 10, 2016

Images are mocked, right? We leaved this behaviour by-default.

I see also adding lodash@4 dep in new piece of code in my PR (which blows OOM). This can't be a reason too... Another stuff is just refactoring.

App itself consumes 108MB of RAM (being launched in dev mode), according to iPhone 6s Plus simulator.

This iissue becomes pretty interesting, let me digg into jest with profiler...

@ColCh
Copy link
Contributor Author

ColCh commented May 10, 2016

@cpojer okay. Nothing to see, just a infinite while loop
I'm sorry, nothing is wrong with jest itself. Closing issue now.

@ColCh ColCh closed this as completed May 10, 2016
@cpojer
Copy link
Member

cpojer commented May 11, 2016

Well, glad Jest could help find some issues with your code! :D

@quentin-
Copy link

it is likely your unit tests set up some expensive listeners and they aren't being cleaned up properly.

Can you elaborate about this? I've tried Jest in React project but I ran into memory problem. When running the following test thousands of time the heap grows until an allocation error is thrown.

// __tests__/Hello-{001-5000}-test.js
import Hello from '../Hello.js';

describe('Hello', () => {
  it('should exist', () => {
    expect(Hello).toBeTruthy();
  });
});
// Hello.js
import React from 'react';
export default () => <span>hello</span>;

@lwlewy
Copy link

lwlewy commented Oct 31, 2016

I'm running into the same problem and my test fails for even the simplest cases:

import React  from 'react';
import { mount, render, shallow } from 'enzyme';

let component = mount(
    <div>test</div>
);
describe('Component', () => {
    it('dies with the full object', () => {
        //console.log('component', component);
        expect(component).toBe(true);
    });
});

Of course this is stupid test what should fail anyway but not with memory error. If I'm trying to use with enzyme's shallow rendering it works, but interestingly also if I comment out expect (if I console log my component variable it looks right).
This is my full stacktrace:

<--- Last few GCs --->

   36806 ms: Mark-sweep 1376.4 (1435.0) -> 1372.8 (1435.0) MB, 1666.0 / 0 ms (+ 2.4 ms in 26 steps since start of marking, biggest step 0.9 ms) [allocation failure] [GC in old space requested].
   38238 ms: Mark-sweep 1372.8 (1435.0) -> 1372.8 (1435.0) MB, 1432.0 / 0 ms [allocation failure] [GC in old space requested].
   39676 ms: Mark-sweep 1372.8 (1435.0) -> 1372.7 (1435.0) MB, 1438.1 / 0 ms [last resort gc].
   41111 ms: Mark-sweep 1372.7 (1435.0) -> 1372.5 (1435.0) MB, 1434.9 / 0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3e38d83c9e59 <JS Object>
    1: sort [native array.js:~918] [pc=0x142fa59c3ea5] (this=0x29726f4c36b1 <JS Array[11]>,aJ=0x3e38d8304189 <undefined>)
    2: arguments adaptor frame: 0->1
    3: printObject(aka printObject) [/home/lkalman/Projects/multiscreenRedux/node_modules/pretty-format/index.js:148] [pc=0x142fa5956f4e] (this=0x3e38d8304189 <undefined>,val=0x2db182598229 <a TokenType with map 0x1ea6b0e2ce79>,indent=0x3...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0xfb0b6c [node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::DeoptimizationInputData::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [node]
 7: v8::internal::LCodeGenBase::PopulateDeoptimizationData(v8::internal::Handle<v8::internal::Code>) [node]
 8: v8::internal::LChunk::Codegen() [node]
 9: v8::internal::OptimizedCompileJob::GenerateCode() [node]
10: v8::internal::Compiler::GetConcurrentlyOptimizedCode(v8::internal::OptimizedCompileJob*) [node]
11: v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions() [node]
12: v8::internal::StackGuard::HandleInterrupts() [node]
13: v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*) [node]
14: 0x142fa4c0961b
Aborted (core dumped)
npm ERR! Test failed.  See above for more details.

It seems to me that when the test fails it tries to pretty-print my component variable but if that is fully mounted pretty-print gets into an infinite loop. My issue is that for some of my real test cases shallow rendering is not enough for me, i need the full tree to check that child elements are mounted properly.

UPDATE
Just noticed that an issue was opened for my problem 2 days ago: #2027

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants