Closed sibelius closed 6 years ago
@sibelius thanks for reporting - why do you think deepCyclicCopy is leaking? I see it in the stack trace but isn't that just where it runs out of memory, not necessarily what is leaking?
it makes sense, maybe the leaking is in another part of the code
I've ran in this repo as well https://github.com/graphql-compose/graphql-compose-mongoose
and the heap is increasing there as well
Can you run with --detectLeaks
?
28 tests failed with leaks
on https://github.com/graphql-compose/graphql-compose-mongoose
is there any way to get more information about it?
I've found this about memory leak on mongoose https://github.com/Automattic/mongoose/issues/2874#issuecomment-388588452:
mongoose.connections.forEach(connection => {
const modelNames = Object.keys(connection.models)
modelNames.forEach(modelName => {
delete connection.models[modelName]
})
const collectionNames = Object.keys(connection.collections)
collectionNames.forEach(collectionName => {
delete connection.collections[collectionName]
})
})
const modelSchemaNames = Object.keys(mongoose.modelSchemas)
modelSchemaNames.forEach(modelSchemaName => {
delete mongoose.modelSchemas[modelSchemaName]
})
I've added this to afterAll jest hook, but it did not worked well
it could be related to this comment https://github.com/facebook/jest/issues/1456#issuecomment-395686090
I am facing the same problema and what I am seeing here is the same message:
1: deepCyclicCopyObject(aka deepCyclicCopyObject) [0x12794b44b231] [/path/to/app/app-server/node_modules/jest-util/build/deep_cyclic_copy.js:~54]...
we added this https://github.com/facebook/jest/issues/6787#issuecomment-409297750 to afterAll hook, it solved most part of memory leak from mongoose
and we solved the other leak part mocking graphql-redis-subscriptions
Mongoose maintainer here. This is not a memory leak, its global state that you need to clean up in your tests. In general, using global state in tests is an anti-pattern. If you want to create a new model for each test, use mongoose.createConnection()
to create a new connection for each test.
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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
🐛 Bug Report
The heap usage keeps increasing when using mongoose
To Reproduce
https://github.com/entria/graphql-dataloader-boilerplate has a simple config that has this issue, but it only crashes when there are a lot of tests (as the memory keeps increasing).
this happens with and without --runInBand option
Expected behavior
the memory heap decreases after a jest
Link to repl or repo (highly encouraged)
https://github.com/entria/graphql-dataloader-boilerplate
Run
npx envinfo --preset jest
Paste the results here:
Below is a print of some tests in a private repo:
And here the crash when the memory heap is not enough anymore:
I think this is related to https://github.com/facebook/jest/issues/6738