question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest: open handle detected

See original GitHub issue

Hi 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:

  1. Create a test file that uses node-fetch
  2. Run the test with jest

Expected behaviour

I would expect to not have any warning/error in the jest output

Screenshots

image

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:open
  • Created 2 years ago
  • Reactions:12
  • Comments:5

github_iconTop GitHub Comments

4reactions
apococommented, Mar 30, 2022

For what it’s worth I’m also experiencing this with node-fetch@2.6.7 and node@16.13.0.

Jest has detected the following 5 open handles potentially keeping Jest from exiting:

  ●  TLSWRAP

      187 |
      188 |     it("my test", async () => {
    > 189 |       const res = await fetch(url, {
          |                              ^
      190 |         agent,
      191 |         method: "PATCH",
      192 |         headers: {

      at node_modules/node-fetch/lib/index.js:1468:15
      at fetch (node_modules/node-fetch/lib/index.js:1437:9)
      ...

…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.

3reactions
salemhilalcommented, Jun 30, 2022

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 the node-domexception polyfill that node-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found