prisma: Jest has detected the following 1 open handle potentially keeping Jest from exiting: CustomGC
Bug description
When I run jest --detectOpenHandles
I get the following:
(Which seems to stem from the Prisma Client)
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● CustomGC
at Runtime._loadModule (../node_modules/jest-runtime/build/index.js:1111:29)
at load (../node_modules/@prisma/client/runtime/library.js:73:326)
at ../node_modules/@prisma/client/runtime/library.js:73:759
at runInChildSpan (../node_modules/@prisma/client/runtime/library.js:70:25817)
at Fr.loadLibrary (../node_modules/@prisma/client/runtime/library.js:73:677)
at Vt.loadEngine (../node_modules/@prisma/client/runtime/library.js:101:557)
at Vt.instantiateLibrary (../node_modules/@prisma/client/runtime/library.js:100:1478)
How to reproduce
npx jest --detectOpenHandles
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
- OS: macOS
- Database: PostgreSQL
- Node.js version: v16.15.1
Prisma Version
prisma : 4.11.0
@prisma/client : 4.11.0
Current platform : darwin-arm64
Query Engine (Node-API) : libquery-engine 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine : migration-engine-cli 8fde8fef4033376662cad983758335009d522acb (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Format Wasm : @prisma/prisma-fmt-wasm 4.11.0-57.8fde8fef4033376662cad983758335009d522acb
Default Engines Hash : 8fde8fef4033376662cad983758335009d522acb
Studio : 0.483.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 29
- Comments: 48 (2 by maintainers)
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.
it’s not just minor issue. it brokes our pipeline on current project. probably by timeout.
I have the same issue and the Heap size is increasing a lot after writing some tests files like @rodrigocipriani has mentioned. I tested lots of approaches to close this warning and decrease memory consumption with Jest + Prisma but without success.
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
^4.11.0
Also seeing this - downgrading to
4.8.1
makes no difference to meI’ve just published it on GitHub for who is interested
https://github.com/rodrigocipriani/prismatest
I’m reproducing in
4.15.0
EDIT
upgrading both
@prisma/client
andprisma
to4.15.0
solved itCan confirm that
^4.11.0
causes open handle issue. Downgrading to4.8.1
removes the issue.Confirmed on
4.14.1
this does not look to be happening any more 🎉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.
true it breaks pipeline. Anyone got it successfully passing the bdd tests? please let me know the version you have?
Environment and Setup prisma : 4.8.1 @prisma/client : 4.8.1 jest : 29.2.2 testcontainers :9.0.1 OS: macOS Database: PostgreSQL 14 Node.js version: v19.2.0
Executes all the test cases and fails at the end with following error
appended by
Jest has detected the following 1 open handle potentially keeping Jest from exiting:
● CustomGC
Please let me know if I you need additional info
Worth noting this happens with
The
--detectOpenHandles
flag is only supposed to help debugging aync operations that keep jest from exiting. As long as you are not using--forceExit
and jest doesn’t get stuck with a warning after running your tests, I wouldn’t worry too much about it.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
await prismaClient.$disconnect()
wouldn’t hurt.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
--detectOpenHandles
to debug this, it would lead me to the wrong assumption that prisma is at fault.FYI running with
DEBUG="prisma:client:libraryEngine"
:4.7.0 didn’t work for me.
@andrewmclagan I’m using
npm
and see the issue.@aravind605 I’m glad that now it’s working for you, thanks for reaching us back. I will not say that this “bug” is fixed because it’s just working with a preview feature, so it’s not so safe to use for now.
It might be due to the previous node modules. once I’ve cleared and re-installed Issue is not appearing any more!! Thanks @rodrigocipriani and team prisma!
Yes. If you can confirm using one of the repositories that were posted, let us know - that makes it easier for us.
@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?
4.8.1 didn’t help… Does anyone have any solution?
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. But the thing is that the Garbage collector seems not working yet.
I’ve created different scenarios to understand the error better. I notice that when you instantiate and use Prisma the heap memory just increases. You can see those in this PR https://github.com/gitnlsn/prisma-test/pull/1
If you run
You’ll notice that HEAP just increases consistently.
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”. Right now I’m not sure that I’ve tested without Typescript. I I’ll get some time tomorrow to test without Typescript.
Didn’t work here also with 4.8.1.
I’ve created a very simple example you can replicate. I’ve tested with nodejs 18, 16 and 14.
package.json
`jest.config.js``
`tsconfig.json``
schema.prisma
sum.ts
sum.test.ts
npm test
EDIT:
With the package.json below, it worked! But with
prisma = 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!
~I suspect this might be an issue with something else interacting with prisma. I encountered the issue after doing a an npm update which updated prisma and @prisma/client from 4.9.0 to 4.12.0 (among other things).~ ~However, after updating just the prisma packages with npm install @prisma/client@4.12.0 prisma@4.12.0, I am not seeing the issue.~
Turns out that I got a tests-not-exiting issue caused by another library (bullmq+nestjs) following an
npm update
. That was causing my jest e2e test suite to hang and not exit. When investigating with--detectOpenHandles
I saw the PrismaCustomGC
warning, so initially thought the issue was Prisma.So I am seeing a
CustomGC
warning from Prisma 4.12.0, but my tests still exit/finish.Using
npm
myself and hitting this so it’s definitely not just pnpm.