-
Notifications
You must be signed in to change notification settings - Fork 1.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
Jest has detected the following 1 open handle potentially keeping Jest from exiting: CustomGC #18146
Comments
Also seeing this. It looks like it was introduced in |
Worth noting this happens with
The Unlike other database connections we're using in our tests (e.g. knex), prisma doesn't seem to require any explicit teardown in order for jest to exit cleanly, however an The main issue I see with this warning about the open prisma handle is that it hides the actual source of the issue from the user. E.g. if jest gets stuck due to an unclosed connection from knex and I use FYI running with
|
@aravind605 I'm not sure your issue is directly related to this. At least in my case, the open handle message does not cause the test suite to fail, it's just a warning when using |
In my case this is my jest config
I'm using detect open handles flag and observe that every test case succeed but at the end suite fails which I believe prisma client is not gracefully closing down and still attempting to search for active connection after the container stopped. |
Also seeing this - downgrading to |
Can confirm that |
I created a repository to reproduce the issue: https://github.com/andrewmclagan/prisma-open-handles It seems it only happens when using pnpm and could possibly be related to this issue, although I think likely its another issue. As this only starts happening on version |
@andrewmclagan I'm using |
Same problem here. I tried downgrading to |
Using |
I've observed this might concern only when we attempt to write integration tests with prisma/client library. But not when the lib is mocked. |
I'm having the same issue here. And it's causing Garbage Collector not to work well and so Heap Memory is huge after some test files. I've tested 4.8.1 and 4.11.0. |
I have the same issue and the Heap size is increasing a lot after writing some tests files like @rodrigocipriani has mentioned. |
it's not just minor issue. it brokes our pipeline on current project. probably by timeout. |
true it breaks pipeline. Anyone got it successfully passing the bdd tests? please let me know the version you have? |
same issue, had to downgrade to 4.7.0 for it to work |
Here 4.7.0 didn't work. Same problem. |
4.7.0 didn't work for me. |
We also see this bug on 4.3.1 |
Turns out that I got a tests-not-exiting issue caused by another library (bullmq+nestjs) following an So I am seeing a |
I think tests will always exit/finish, I think there's a timeout/threshold for how long a test can take before it skips and continues. This is likely why you see the error, but it will always finish. I do not have |
Libraries I'm using: "dependencies": {
"@opentelemetry/api": "^1.3.0",
"@opentelemetry/auto-instrumentations-node": "^0.36.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.35.0",
"@opentelemetry/sdk-node": "^0.35.0",
"@prisma/client": "^4.11.0",
"@splitsoftware/splitio": "^10.21.1",
"@types/express-rate-limit": "^5.1.3",
"@types/rate-limit-redis": "^1.7.4",
"@types/redis": "^2.8.32",
"assert-plus": "^1.0.0",
"cls-hooked": "^4.2.2",
"dotenv": "^16.0.3",
"express": "^4.17.3",
"express-rate-limit": "^5.3.0",
"kafkajs": "^2.0.2",
"lusca": "^1.7.0",
"module-alias": "^2.2.2",
"mongodb": "^4.13.0",
"node-fetch": "^2.6.7",
"pg": "^8.7.3",
"rate-limit-redis": "^2.1.0",
"redis": "^3.1.2",
"tsoa": "^5.1.1",
"winston": "^3.6.0"
},
"devDependencies": {
"@faker-js/faker": "^7.1.0",
"@guidecx/config-prettier": "^1.0.0",
"@types/assert-plus": "^1.0.4",
"@types/cls-hooked": "^4.3.3",
"@types/cors": "^2.8.12",
"@types/eslint": "^7.28.0",
"@types/express": "^4.17.6",
"@types/jest": "^29.4.2",
"@types/lusca": "^1.7.1",
"@types/node": "^16.18.16",
"@types/node-fetch": "^2.6.1",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"concurrently": "^7.0.0",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"docker-compose": "^0.23.17",
"dotenv-cli": "^6.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"husky": "^7.0.4",
"jest": "^29.5.0",
"lint-staged": "^12.3.7",
"nodemon": "^2.0.12",
"prettier": "2.3.2",
"prisma": "^4.11.0",
"supertest": "^6.1.4",
"ts-jest": "^29.0.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"uuid-random": "^1.3.2"
} |
Managed to get ours to work with 4.8.1 |
Didn't work here also with 4.8.1. I've created a very simple example you can replicate.
{
"name": "prismatest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --detectOpenHandles"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^4.12.0",
"prisma": "^4.12.0"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.3"
}
} `jest.config.js`` /** @type {import('ts-jest').JestConfigWithTsJest} */
module. Exports = {
preset: "ts-jest",
testEnvironment: "node",
}; `tsconfig.json`` {
"compilerOptions": {
"esModuleInterop": true
}
}
function sum(a: number, b: number): number {
return a + b;
}
export default sum;
import { PrismaClient } from "@prisma/client";
import sum from "./sum";
const prismaClient = new PrismaClient();
test("adds 1 + 2 to equal 3", () => {
expect(sum(1, 2)).toBe(3);
});
EDIT: With the package.json below, it worked! But with {
"name": "prismatest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest --detectOpenHandles"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^3.15.2",
"prisma": "^3.15.2"
},
"devDependencies": {
"@types/jest": "^29.5.0",
"jest": "^29.5.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.3"
}
} EDIT 2: 🥲 It seems that with Prisma 3 it didn't work, it stops showing the CustomGC error, but the Memory use is even worse! |
Thanks for digging in to create a minimum reproduction @rodrigocipriani With rolling prisma back so far, I have to wonder if this has always been going on for the most part, but maybe Jest updated something that does a better job of catching this problem, so now we've been seeing it. |
Maybe you're right, now it's making better job catching problems. But GC still not working, and memory heap size just increases each test. But only when Prisma is "in the game". |
I faced the same issue with customGC, preventing jest from exiting. Downgrading to 4.8.1 removed the issue. My dependencies and devDependencies are the following. "dependencies": {
"@prisma/client": "4.8.1",
"express": "^4.18.2",
"zod": "^3.21.4",
"zod-express-middleware": "^1.4.0"
},
"devDependencies": {
"@types/express": "^4.17.17",
"@types/jest": "^29.5.0",
"@types/supertest": "^2.0.12",
"jest": "^29.5.0",
"prisma": "4.8.1",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"typescript": "^5.0.3"
}, |
@gitnlsn still no luck with 4.8.1 :( |
I've just tested without Typescript and still not having CustomGC error. But the Heap size decreased a lot. |
I've just published it on GitHub for who is interested |
I've checked it. Ive cloned it and executed it. I found no issues when running sum.test.*. But the issue appears when i establish a connection and make a create operation with prisma. When I downgrade to version 4.8.1. The issue indeed disapppears. https://github.com/gitnlsn/prisma-test In this repository there are 2 branches, one for each case. In the readme, I wrote the results from my environment. Also, I guess the issue might not be related to I hope those information help to debug it. |
Thanks for the tests. I just realize that I was using "^4.8.1" instead of "4.8.1". So after this I stopped receiving the CustomGC error. I've created different scenarios to understand the error better. I notice that when you instantiate and use Prisma the heap memory just increases. If you run npm test --resolveJsonModule ./withPrismaActionsWithoutTypescript/user*
or
npm test --resolveJsonModule ./withPrismaActions/user* You'll notice that HEAP just increases consistently. |
4.8.1 didn't help.. |
@janpio What do we need to get the "unconfirmed" label removed? Is there any additional information required? Others have added example repositories as an example for reproduction. Does confirmation need to happen from an internal team? |
Yes. If you can confirm using one of the repositories that were posted, let us know - that makes it easier for us. |
4.8.1 didn't help me either! |
Downgrading to {
"dependencies": {
"@prisma/client": "4.8.1",
"prisma": "^4.8.1"
}
} However, I have successfully gotten I noted that my integration tests that use the jest // setupFilesAfterEnv script with --runInBand
afterEach(async () => {
/** After each test, close database connections */
await prisma.$disconnect();
}); I tried adding this I ended up resolving it by ensuring things that used/loaded the prisma client were mocked correctly in my unit tests (which... it should of already been but because of some changes I made it wasn't correctly mocked anymore 🙃) |
The tests I made with:
seems to solve the Heap Memory problem. I'm not sure if NodeJS <= 18 will solve it, I haven't tested enough EDIT:
|
Prisma 4.13.0 and Prisma 4.13.0 stable versions are released.
|
Hey @aravind605 ... I didn't try to update this repo to test it. I did it in my other repo and it worked. If I have some time I'll update the test repo you've mentioned. Let me know if you tested with the jsonProtocol. |
It might be due to the previous node modules. once I've cleared and re-installed |
@aravind605 I'm glad that now it's working for you, thanks for reaching us back. |
Jest has detected the following 1 open handle potentially keeping Jest from exiting: ● CustomGC
same for prisma version 4.9.0 |
Using #18146 (comment) (which doesn't use the I could confirm the bug with Prisma versions
On the good news: I cannot reproduce with Could you try one of these newer version and let us know? I'll close this as fixed now based on the reproduction. |
Confirmed on |
I'm reproducing in EDIT upgrading both |
Bug description
When I run
jest --detectOpenHandles
I get the following:(Which seems to stem from the Prisma Client)
How to reproduce
Expected behavior
There should be no open handles left over from Jest tests to prisma. There should be no open DB handles anyways since the tests are not connecting a database.
Prisma information
Cannot share on the given project unfortunately.
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: