Prisma not disconnecting after jest run (NestJs project)
See original GitHub issueBug description
I am running end to end tests against a psql database using Jest in a NestJs project. The test runner does not seem to be closing the Prisma connection upon completion… I am seeing the following warning.
Jest did not exit one second after the test run has completed.
This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
If I add the --detectOpenHandles flag i see the following: Jest has detected the following 1 open handle potentially keeping Jest from exiting:
TCPSERVERWRAP
22 | it('It should create a dummy org', async () => {
23 | const { body } = await request(app.getHttpServer())
> 24 | .post('/organizations')
| ^
25 | .expect(201);
26 | expect(body).toHaveProperty('organizationId');
27 | });
at Test.Object.<anonymous>.Test.serverAddress (../node_modules/supertest/lib/test.js:61:33)
at new Test (../node_modules/supertest/lib/test.js:38:12)
at Object.obj.<computed> [as post] (../node_modules/supertest/index.js:27:14)
at Object.<anonymous> (recreate.e2e-spec.ts:24:8)
This issue was not present when I was using TypeOrm, but after making the move to Prisma I started seeing it
The below is just additional information of a side effect caused by this, and is not part of the reproduction steps so I am not including the stack trace I was getting around this issue by using the forceExit flag so that my CI pipeline could at least pass, however I have gotten to a point where there are too many connections, and my tests start throwing errors. The following error is what I am seeing:
Error: Error querying the database: db error: FATAL: sorry, too many clients already
How to reproduce
- Clone the repository:
- run
npm install
- run
docker-compose up -d
- run
npm run test:e2e
Expected behavior
The test runner should exit gracefully
Prisma information
This is all in the docker file included in the repo
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: v12.10.0
The issue is also occurring on my circle ci build, using node: circleci/node@4.1 and image: ubuntu-1604:202007-01
Prisma Version
2.30.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Can you also reproduce this change in behavior @TasinIshmam with the most recent update?
@TasinIshmam I tried to incorporate this into my actual project, and it did not work. However I did see the notification to update to the new major version (To be precise ^3.4.2"). This seems to have fixed the problem 100% Without the need for your suggestion above.
Thanks very much for your help, I put this issue off for too long, and I am super happy I have finally overcome it.