-
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
Prisma client does not clean up itself after test #13575
Comments
Thanks for reporting this. We are aware of the issue. I'm closing this issue. You can follow along #12339 |
Reopening as it has its own reproduction that hopefully will help us understand the issue properly. |
I tried https://github.com/codeledge/prisma-memory-leak-repro as is on Node.js v20.8.1 I replaced the contents of
And then ran
I tried upgrading the dependencies with I now switched to Node.js
and failing with the following, more minimalist test: import { PrismaClient } from "@prisma/client";
describe("schema", () => {
afterAll(async () => {
const prismaClient = new PrismaClient();
});
test("empty test", async () => {
});
}); with
|
Hey @ogroppo
Test on Node import prismaClient from "../prisma/prismaClient";
describe("schema", () => {
afterAll(async () => {
await prismaClient.$disconnect();
});
test("Deleting parent row in 1-to-n trows error", async () => {
const user = await prismaClient.user.findFirst();
expect(user).toBeFalsy();
});
}); Yields
The following causes the test to pass. import prismaClient from "../prisma/prismaClient";
describe("schema", () => {
test("Deleting parent row in 1-to-n trows error", async () => {});
});
I tried downgrading to pnpm On node import { PrismaClient } from "@prisma/client";
describe("schema", () => {
afterAll(async () => {
const prismaClient = new PrismaClient();
});
test("empty test", async () => {});
}); I run into the following error:
Commenting out the client yields a passing test.
Updating to Prisma import { PrismaClient } from "@prisma/client";
describe("schema", () => {
afterAll(async () => {
const prismaClient = new PrismaClient();
});
test("empty test", async () => {});
}); Yielded:
While the following passed import { PrismaClient } from "@prisma/client";
describe("schema", () => {
afterAll(async () => {
// const prismaClient = new PrismaClient();
});
test("empty test", async () => {});
}); Some quick graphing I did describe("schema", () => {
memoryLogger.log();
afterAll(async () => {
await prismaClient.$disconnect();
});
for (let i = 0; i < 100000; i++) {
memoryLogger.log();
test("test", async () => {
const user = await prismaClient.user.findFirst();
expect(user).toBeFalsy();
});
memoryLogger.log();
}
}); vs describe("schema", () => {
memoryLogger.log();
afterAll(async () => {});
for (let i = 0; i < 100000; i++) {
memoryLogger.log();
test("test", async () => {
const user = null;
expect(user).toBeFalsy();
});
memoryLogger.log();
}
}); |
@ogroppo It's been a while since you opened this issue. As you can see, we investigated and posted results, but we didn't find an actual memory leak. Jest If you have a reproduction where a memory leak can be observed, we will be happy to attempt a reproduction and investigate again. I hope I can create a code template in the future with some guidelines to help with potential memory leaks issue in the future (to be done) |
Bug description
It has been noticed that using prisma client in integration tests (jest), leads to memory usage building up and never being released (--logHeapUsage)
the $disconnect method seems not to have the desired effect, still the error is
Similar issues
#12153
#8989
How to reproduce
minimal repo:
https://github.com/codeledge/prisma-memory-leak-repro
Just
pnpm i && pnpm t
it runs a simple test with jest and the--detectLeaks
flagExpected behavior
the client should be destroyed and leave no traces after test process finishes
Prisma information
https://github.com/codeledge/prisma-memory-leak-repro
Environment & setup
Prisma Version
prisma : 3.14.0
@prisma/client : 3.14.0
Current platform : darwin
The text was updated successfully, but these errors were encountered: