jest: open handle detected
See original GitHub issueHi all, I would like to report a strange behaviour that started to happen after upgrading to the latest release. When running our test suite, I noticed a warning message after completion saying:
Ran all test suites matching /src/i.
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● MESSAGEPORT
at Object.<anonymous> (../../node_modules/node-domexception/index.js:6:12)
at async Promise.all (index 16)
at async Promise.all (index 3)
at async Promise.all (index 1)
at TestScheduler.scheduleTests (../../node_modules/@jest/core/build/TestScheduler.js:333:13)
at runJest (../../node_modules/@jest/core/build/runJest.js:404:19)
at _run10000 (../../node_modules/@jest/core/build/cli/index.js:320:7)
at runCLI (../../node_modules/@jest/core/build/cli/index.js:173:3)
Doing a rollback to node-fetch@3.1.1
makes the warning disappear. I would assume that something has changed in the latest release that is causing this issue.
Reproduction
Steps to reproduce the behaviour:
- Create a test file that uses
node-fetch
- Run the test with
jest
Expected behaviour
I would expect to not have any warning/error in the jest output
Screenshots
Your Environment
software | version |
---|---|
node-fetch | v3.2.0 |
node | v16.13.0 |
npm | 8.1.0 |
Operating System | macOs Monterey 12.1 |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:12
- Comments:5
Top Results From Across the Web
closing open handles detected by jest - Stack Overflow
1 Answer 1 · add "jest --detectOpenHandles" to "test" in package.json to see the openhandles for Debugging · check your db connection (most...
Read more >detectOpenHandles prints nothing, just hangs #9473 - GitHub
One improvement I want to make is print "sorry, we found no open handles" or some such so it doesn't seems like Jest...
Read more >Jest has detected the following 1 open handle ... - Temporal
Hi, im using Jest to test Temporal workflows/activities as wrote in the following doc: Im getting the following error: I guess because the ......
Read more >How to fix err Jest has detected the following 3 open handles ...
Here's what I did to solve this problem. afterAll(async () => { await new Promise(resolve => setTimeout(() => resolve(), 10000)); // avoid jest...
Read more >Troubleshooting - Jest
To debug in Google Chrome (or any Chromium-based browser), open your browser and go to chrome://inspect and click on "Open Dedicated ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For what it’s worth I’m also experiencing this with
node-fetch@2.6.7
andnode@16.13.0
.…and I just now realized that in all cases they’re tests where I have a request body and the server responds with an error. It appears that the request stream is not aborted after the server responds.
I had the same problem as above (the
MESSAGEPORT
one) with essentially the same stack trace. I thought it must have something to do with thenode-domexception
polyfill thatnode-fetch
uses. The open handle error points to the line where the new MessageChannel is created in the polyfill, but patching the polyfill to explicitly close its ports (i.e.port.close()
) didn’t fix the problem.It turns out I was starting the web server I was about to test more than once, inadvertently. I wasn’t closing the extra instance, which caused my tests to hang. Something about Jest’s open handle detection doesn’t like that MessageChannel hack, but it seems like Jest’s detection is also a bit of a red herring. Fixing the server problem caused my tests to pass without any open handler warnings, no changes to
node-fetch
necessary.I’m leaving this message as a bit of a warning to other people; if you think it’s
node-fetch
, pick through your code again and see if you’re not inadvertently missing something.