"MaxListenersExceededWarning: Possible EventEmitter memory leak detected" when creating models with `autoCreate: true` before `mongoose.connect()`
See original GitHub issueDo you want to request a feature or report a bug? Bug report
What is the current behavior?
When creating more than 10 models MaxListenersExceededWarning
appears
If the current behavior is a bug, please provide the steps to reproduce. Create more than 10 models like this:
mongoose.model<DocumentType, ModelType>(name, schema);
If you are using TypeScript, please include your tsconfig.json
{
"compilerOptions": {
"target": "es5" ,
"module": "commonjs" ,
"declaration": true ,
"declarationMap": true ,
"sourceMap": true ,
"outDir": "./dist" ,
"strict": true ,
"baseUrl": "./",
"paths": {
"@sm-errors": [
"./common-library/errors"
],
"@sm-microsoft-graph-api": [
"./common-library/microsoft-graph-api"
],
"@sm-shared-models": [
"./common-library/shared-models"
],
"@sm-shared-services": [
"./common-library/shared-services"
],
"@sm-lib": [
"./common-library/lib"
]
},
"esModuleInterop": true ,
"skipLibCheck": true ,
"forceConsistentCasingInFileNames": true
},
"exclude": [
"node_modules",
"dist"
]
}
What is the expected behavior? Should create more models without warnings
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version.
mongoose: "^5.9.27",
Node 12
MongoDB 4.2.2
Currently I solved the issue by calling the following function each time before creating models:
mongoose.connection.setMaxListeners(MAX_LISTENERS_COUNT);
but I think there should be another solution for this.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
App crash && Possible EventEmitter memory leak detected
I am trying to add a new feature to an existing (Node.js, express and MongoDB) project (Help pages). I began by adding two...
Read more >[NODE-2123] MaxListenersExceededWarning caused by ...
I recently added `useUnifiedTopology: true` to my connection ... (node:23551) MaxListenersExceededWarning: Possible EventEmitter memory leak ...
Read more >Mongoose v6.8.1: Connection
Returns a promise that resolves when this connection successfully connects to MongoDB, or rejects if this connection failed to connect.
Read more >use emitter.setmaxlisteners() to increase limit - You.com
I'm getting the error warning: possible EventEmitter memory leak detected. 11 reconnect listeners added. Use emitter.setMaxListeners() to increase limit. app.
Read more >Events | NestJS - A progressive Node.js framework
forRoot() call initializes the event emitter and registers any declarative event listeners that exist within your app. Registration occurs when the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It also happens when I use
autoCreate: true
on Schemas. Without that option it is ok@vkarpov15 its very finicky but I can reproduce it but I’m not sure what triggers it.