jest: Using lodash causes "open handles" warnings
🐛 Bug Report
Something about Lodash causes Jest to detect “open handles”
To Reproduce
Run jest with --detectOpenHandles
and require lodash. I’m not sure what the exact conditions going on here, but it’s pretty reliably reproducible with the repo below.
The behavior looks like this:
Jest has detected the following 2 open handles potentially keeping Jest from exiting:
● PROMISE
at Function.resolve (<anonymous>)
at Object.<anonymous> (node_modules/lodash/_getTag.js:37:32)
● PROMISE
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
> 3 | require("lodash");
| ^
4 | describe(`lodash`, () => {
5 | it(`causes these tests to show open handles`, () => {
6 | expect(1).toEqual(1);
at Function.resolve (<anonymous>)
at runInContext (node_modules/lodash/lodash.js:6069:36)
at Object.<anonymous> (dist/test/do-lodash-things.js:3:1)
Expected behavior
I wouldn’t expect to see open handles for require()
calls
Link to repo
git clone https://github.com/alexturek/jest-lodash-handles-bug
cd jest-lodash-handles-bug
yarn
tsc
yarn test
Run npx envinfo --preset jest
aturek@aturek-mbpro ~/oss/jest-lodash-handles-bug> npx envinfo --preset jest
npx: installed 1 in 3.361s
System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Binaries:
Node: 8.9.1 - ~/.nvm/versions/node/v8.9.1/bin/node
Yarn: 1.7.0 - ~/.yarn/bin/yarn
npm: 5.5.1 - ~/.nvm/versions/node/v8.9.1/bin/npm
npmPackages:
@types/jest: ^23.1.4 => 23.1.4
jest: 23.3.0 => 23.3.0
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 25
- Comments: 18 (11 by maintainers)
Consistently seeing the same issue:
See also https://github.com/petkaantonov/bluebird/issues/1541
As mentioned there, I think the fix is to ignore promises as they don’t keep the process open anyways
@SimenB I might be able to spend time on a fix. What’s the package I should start in?
jest-cli/.../collectHandles.js
?@SimenB Maybe I had to explain why I think some of the stack traces that I posted seem related to me.
lodash
andsequelize
stack traces end up in theFunction.resolve
call. Couldn’t this be caused by the same issue ? Thought this could be useful.I’m removing the other stack trace so that it doesn’t generate confusion.
Running into multiple of this issues on jest 23.4.0
I think we should rework it to wait for some time (maybe 1000ms to match when we hint about the flag) before collecting open handles. The process doesn’t hang when importing lodash which is the thing the flag is meant to help you find