1
My database connectorMongo for nodejs, after a while running triggers the ENOBUFS error, knocking down all the tcp connections from the computer.. other apps claim tcp exhaustion.. however I could not solve the problem, it seems after each query the application leaves the connection open.. To diagnose regarding the error source was made the "crash" of mongodb service and was reestablished the connections immediately.
below is the data
connection string
const mongoUrl = 'mongodb://localhost:27017/?readPreference=primary&appname=meuAplicativo&ssl=false&authSource=database01&keepAlive=false&poolSize=5&agent=false';
open connection to server
MongoClient.connect(mongoUrl, { "useUnifiedTopology": true, /*directConnection :true,*/ keepAlive: false, maxPoolSize:20}, async function(err, client) {
if(err) throw err
// entra na base de dados
const database = client.db(mongoDBName);
findAndModifyTags(__postBody['data'], database, 0, res, null);
});
Query
//seleciona coleção de dados
tagCollection = database.collection('values');
//procura e atualiza registro
tagCollection.updateOne(query, update,{returnNewDocument: false, upsert: true, new: true}, (error) =>
{
if(!error) {
console.log(`Successfully updated document`)
//console.log(`Successfully updated document: ${JSON.stringify(doc)}.`)
} else {
console.log("No document matches the provided query.")
console.log(error)
}
//resposta positiva
res.write("{'status': 'ok'}");
res.end();
});
Details of the Error
debug -> 2021-3-19 9:45:56 AM notnull
debug -> 2021-3-19 9:45:56 AM notnull
debug -> 2021-3-19 9:45:56 AM has data
(node:28792) UnhandledPromiseRejectionWarning: MongoServerSelectionError: connect ENOBUFS 127.0.0.1:27017 - Local (undefined:undefined)
at Timeout.waitQueueMember.timer.setTimeout [as _onTimeout] (E:\Projetos\Telemetria Raspberry Zero\node_modules\mongodb\lib\core\sdam\topology.js:438:30)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
(node:28792) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 357)
as can be seen, I have already made the pool reduction and some more procedures, but I still continue with the error
At what point is the connection created? Could add the code that contains the creation of the connection and at which time of the life cycle is made the communication with the database?
– Danizavtz
In fact it is already described above... in the first excerpt Mongoclient.connect, in the application lifecycle it basically receives a post request and adds to the database, requests are made every 10 seconds for each client, but per hour the test is with only one client it for after 2160 requests on average
– user7331387
I asked because in my mongodb applications I have only 1 connection per process. I never had this problem, maybe if I could see how it is structured my application will help.
– Danizavtz
in case you open the connection and leave it open for all requests? I’ll try, to see if it improves
– user7331387
If you want to have a project to be inspired you can see in my github the project
tokenAuthMongo
.– Danizavtz
Man, I don’t know if it worked out, but I created an answer with the essential parts to a possible solution.
– Danizavtz