-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
TLSWRAP open handle wrongly detected with MongoDB connections #11665
Comments
I can confirm having exactly the same issue with Jest |
I'm having the same issue as well |
I was having the same problem and blaming Jest or the mongodb node driver. The reason for the problem was that I wasn't actually dealing with a singleton like I was lead to believe: even though I was following the text-book standard for connection pooling in an application, each file ran by Jest was creating a new connection when doing an import of my I suggest to verify if the same problem is happening to you; my solution so far has been to add an Now my jest runs close without forcing and no open handles are left. |
I detected a similar issue using the // src/helper/redis.ts
async function withRedis(handle: (r: IORedis.Redis) => Promise<void>): Promise<void> {
const redis = new Redis(Number(process.env.REDIS_PORT), process.env.REDIS_HOSTNAME, {
password: process.env.REDIS_PASSWORD,
tls: true as any,
});
try {
await handle(redis);
} finally {
await redis.quit();
}
}
// src/some.spec.ts
beforeEach(async () => {
await withRedis(async redis => {
const keys = await redis.keys(`*${process.env.KEY_PREFIX}*`);
for (const key of keys) {
await redis.del(key);
}
});
}); It produces sporadically the following warning with
|
I have the same issue with something as simple as this using axios
"axios": "^0.21.4", |
The problem seems to be that the Async hooks module in Node doesn't emit a In Jest we have today something like: if (type === 'PROMISE' ||
type === 'TIMERWRAP' ||
type === 'ELDHISTOGRAM' ||
type === 'PerformanceObserver' ||
type === 'RANDOMBYTESREQUEST' ||
type === 'DNSCHANNEL' ||
type === 'ZLIB'
) return; These are all problematic hook types that are simply ignored. And "TLSWRAP" should probably be added to this list. (Since there is always an underlying socket object which is what we're really interested in.) But to test this, we'd have to set up a TLS session object which is not exactly trivial. |
Any news on this? Stumbled over this problem just now and desperately trying to find a solution for it... |
@dornfeder I have success with simply adding a test in the snippet above for "TLSWRAP". But to test that out is a lot of CI/CD work setting up a certificate, etc. |
Great catch @malthe! I can confirm that adding TLSWRAP to the ignore list in collectHandles seems to get rid of the issue for MongoDB connections. Would be nice to get some eyes on this. |
@odziem |
I face similar error it was solve by removing --detectOpenHandles, |
@ruthcyg but that is arguably the wrong solution. |
Guys any updates here? |
Having the same issue with Axios |
still have same issue here. any updates? |
@malthe would you say that's a bug in node? Or should we just ignore the type? |
@SimenB it's some time since I started the thread, but I think it's just a bug in jest really:
|
Im having same issues, there is nothing else I can do to awai the mongoose.connect or mongoDB.connect async. |
I'm having the same problem while doing:
The error is: `Jest has detected the following 1 open handle potentially keeping Jest from exiting: ● TCPWRAP
I have tried so many things but without any result. I think the problem is that database connection isn't really closed. I tried: For some reason Closing database connection immediately on application start may cause problems in units that actually use database connection. As explained in the guide, MongoDB connection should be at the end of test. Since default Mongoose connection is used, it can be:
Anything of those worked for me, but I think the solution is close. If anyone see anything with that please let us know. |
I am also experiencing this issue, but for me it is caused by |
I have a much simpler reproduction for this issue: const tls = require('tls');
describe('Test', () => {
it("runs a test", () => {
const socket = new tls.TLSSocket();
socket.destroy();
});
}); Prints:
|
const tls = require("tls");
describe("Test", () => {
it("runs a test", async () => {
let socket = new tls.TLSSocket();
socket.destroy();
await new Promise(r => setTimeout(r, 0));
// @ts-ignore
gc();
});
}); This seems to do the trick, but I'm not sure how I should open the PR in jest. Looks like it's better left to you to decide. |
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. |
💥 Regression Report
Running Jest with --detectOpenHandles detects a TLSWRAP potential open handle on MongoDb connections, even if they are properly closed in an "afterAll" enclosure and jest exits without issues. The exact message is:
This seems to happen with MongoDb's official NodeJs driver, and, by extension, any other packages that use that driver (in my case I got it with mongoose and connect-mongo-session)
Last working version
Worked up to version: 26.6.3
Stopped working in version: 27.0.0
To Reproduce
NOTE: A valid MongoDB URI is needed to reproduce this issue.
Within an empty directory:
Expected behavior
No open handles should be found.
Link to repl or repo (highly encouraged)
Use the code snippet provided above.
Run
npx envinfo --preset jest
Paste the results here:
Thank you for your help! <3
The text was updated successfully, but these errors were encountered: