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

The process exits normally, but I get an open handle error. #9982

Closed
CatsMiaow opened this issue May 6, 2020 · 15 comments · Fixed by #11470
Closed

The process exits normally, but I get an open handle error. #9982

CatsMiaow opened this issue May 6, 2020 · 15 comments · Fixed by #11470

Comments

@CatsMiaow
Copy link

CatsMiaow commented May 6, 2020

  • Node.js v12.16.2
  • Jest v26.0.1

Related issues #6423 (comment)

This code terminates the process normally but Jest gives an open handle error.

import { promises } from 'dns';
//= const { promises } = require('dns');

const { Resolver } = promises;
const resolver = new Resolver();
const servers = resolver.getServers();
console.log(servers);
@thymikee
Copy link
Collaborator

thymikee commented May 6, 2020

Can you provide a minimal repro which can be downloaded?

@CatsMiaow
Copy link
Author

CatsMiaow commented May 6, 2020

@Cosmin-Gramada
Copy link

Still seeing this issue in the latest version Jest to date, v26.4.0.

@cschwebk
Copy link

Still seeing this issue.

Node 14.15.0
Jest 26.4.2

@mifi
Copy link

mifi commented Jan 6, 2021

Is there any workaround? it causes jest to hang forever and never complete.

@mksmzpsv
Copy link

@mifi you can use --forceExit CLI option, but it's just a workaround. I hope it will be fixed soon.

@j
Copy link

j commented Jan 29, 2021

This was an annoying for us as well.

I noticed if you just raise the timeout and give the DNS time to close, it won't emit this error, so another potential workaround?

yarn test --testTimeout=10000

@LinusU
Copy link
Contributor

LinusU commented Mar 2, 2021

I'm seeing this as well, seems to have started when I upgraded from Jest 25 to 26 and switched to the jest-circus runner.

@ShivamJoker
Copy link

I am also having the same issue please fix this now its been there from long time.

@dahlmo
Copy link

dahlmo commented May 26, 2021

Same symptoms here w/Jest v.26.0.23 and node v14.15.0. The minimal repro provided by @CatsMiaow (https://github.com/CatsMiaow/jest-issues-9982) seems to validate the issue on my end.

@seahindeniz
Copy link

seahindeniz commented May 27, 2021

Same happens here

image

repo https://github.com/seahindeniz/jest-dnschannel-issue

@joshkel
Copy link
Contributor

joshkel commented May 28, 2021

After looking into this, I think the DNSCHANNEL is harmless. If I'm understanding the code correctly, the Resolver class from Node.js's dns module automatically creates one as part of its ChannelWrap C++ class that it uses to wrap the c-ares resolver library. (See here and here.)

However:

Based on that, I'm thinking that DNSCHANNEL is a false positive: it's harmless, it's not actually keeping Jest from exiting, and if Jest is kept from exiting, it's because of some other resource (which may not be showing up correctly for various reasons - see, e.g., #11464).

@seahindeniz
Copy link

seahindeniz commented May 28, 2021

Yes, it's probably a false positive one, but I believe it's interrupting the development process. The logs are too annoying, and it eats too much line from the terminal and leads us to scroll up every time.

I think I've faced this issue after upgrading the Jest from v26.6.3 to v27.0.1

@Mr0grog
Copy link
Contributor

Mr0grog commented May 28, 2021

@joshkel yeah, I think you’re correct about DNSCHANNEL — it’s also explicitly marked as a weak reference in the Node.js source (just a couple lines after one of the ones you linked), so Jest probably shouldn’t track it. There’s actually an explicit block of code for this kind of thing (async stuff that shouldn’t prevent the process from exiting or be tracked), but DNSCHANNEL just isn’t included there and probably should be: https://github.com/facebook/jest/blob/2cb20e945a26b2c9867b30b787e81f6317e59aa1/packages/jest-core/src/collectHandles.ts#L65-L73

(I made some improvements to this area of the codebase just before the Jest 27 release, so I’m at least a little familiar with what’s going on there. 🙂)

Mr0grog added a commit to Mr0grog/jest that referenced this issue May 28, 2021
It turns out that Node.js only holds a weak reference on `DNSCHANNEL` async resources, so they won't prevent a process from exiting. This changes `--detectOpenHandles` to ignore `DNSCHANNEL` handles.

Because Jest dedupes open handles by their stack trace, and async handles indirectly opened from *other* async handles get the same stack trace as the first handle, tracking the `DNSCHANNEL` resource can obscure other, more meaningful handles that were indirectly created and actually *are* causing the process to hang. Fixing this makes it a little easier for users to identify the actual issue that might be causing their tests to hang.

Fixes jestjs#9982.
chriswk pushed a commit to Unleash/unleash that referenced this issue May 28, 2021
* Migrate to jest
* Use --force-exit until dns close handle issue jestjs/jest#9982

Co-authored-by: Ivar Conradi Østhus <ivarconr@gmail.com>
@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 Jun 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.