Skip to content
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

MaxListenersExceededWarning #10762

Closed
barrydevp opened this issue Sep 22, 2021 · 2 comments
Closed

MaxListenersExceededWarning #10762

barrydevp opened this issue Sep 22, 2021 · 2 comments
Assignees
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@barrydevp
Copy link

barrydevp commented Sep 22, 2021

Do you want to request a feature or report a bug?
bug

What is the current behavior?
Using useDb for reuse connection to replicaset mongodb server in multi-tenant architecture, after call useDb for 100 different database names. The nodejs Warning occur:

(node:35699) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [MongoClient]. Use emitter.setMaxListeners() to increase limit
(node:35699) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [MongoClient]. Use emitter.setMaxListeners() to increase limit
(node:35699) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [MongoClient]. Use emitter.setMaxListeners() to increase limit
(node:35699) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 parseError listeners added to [MongoClient]. Use emitter.setMaxListeners() to increase limit

If the current behavior is a bug, please provide the steps to reproduce.

const conn = mongoose.createConnection(uri, {
           useUnifiedTopology: true,
})

for(let i = 0; i < 100; i++) {
       const db = conn.useDb(`db_${i}`)
}

What is the expected behavior?
The warning was not shown

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Nodejs: 12.22.1
mongoose: 5.13.9

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Sep 22, 2021
@IslandRhythms
Copy link
Collaborator

So it reproduces on both 5.13.9 and latest, however, the error message prints once on latest whereas it prints 4 times on 5.13.9. How do you want to proceed @vkarpov15

const mongoose = require('mongoose');

async function test() {
   const conn = await mongoose.createConnection('mongodb://localhost:27017/', {
    useUnifiedTopology: true});
    for(let i = 0; i < 100; i++) {
        const db = conn.useDb(`db_${i}`);
    }
}


test();

@barrydevp
Copy link
Author

Can you guys fix on the top of version 5.x, for some reason we cannot upgrade to version 6.x :( tks.

@vkarpov15 vkarpov15 added this to the 6.0.11 milestone Sep 24, 2021
vkarpov15 added a commit that referenced this issue Oct 11, 2021
…ent emitter memory leak warnings with `useDb()`

Fix #10762
@vkarpov15 vkarpov15 modified the milestones: 6.0.11, 5.13.11 Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants