Jest hangs when running in docker with some CPU / RAM config

Viewed 862

Some days ago I upgraded my codebase from jest 26 to 27.

Running tests in my local environment worked like a charm but, when I tried to run them on my CI machine, the tests "never" stop.

Actually, in CI, the process exited correctly when trying to run tests sequentially but not in parallel, eg with --runInBand --detectOpenHandles --forceExit.

I tried to build and run the same docker locally... and it worked.

Changing randomly some docker's CPU / RAM configs, I achieved the same result: the process hangs.

docker config

Tests hanging: tests hanging

Running top in docker: docker top

As you can see, it's not a problem of CPU / RAM considering what top says.

Do you have any hints?

Do you need more information?

2 Answers

TL;DR:

I fixed memory leaks by downgrading node from 16.13.2 to 16.10.0.

Details:

Based on Mattia Larentis answer:

I had the same problem, code and tests were written for client app, used packages:

  • node: 16.13.2
  • jest: 27.4.7
  • ts-jest: 27.1.3
  • typescript: 4.5.5

After debugging and analysing jest tests, I detected memory leaks too, using:

node --expose-gc ./node_modules/.bin/jest --logHeapUsage

Then I analysed node heap snapshots (for more info see Your Jest Tests are Leaking Memory).

I found a lot of strings, containing transpiled TS code.

I went to ts-jest & jest repos to look for issues about memory leaks.

I found these:

Then, I downgraded node version from 16.13.2 to 16.10.0, checked memory leaks using

node --expose-gc ./node_modules/.bin/jest --logHeapUsage

And found that problem was gone.

Related