Hi,
We are using mongodb server mongo:6.0. When we upgrade the native nodejs driver for mongodb from 5.3 to 6.4, we run into MongoNetworkErrors.
node version: 20.11.1, As per the official doc of mongodb, we initialize our client instance as following.
We are using MongoClient to connect to the Azure AKS pod in a cluster that has mongodb server mongo:6.0 image deployed. We are using connection pools and application wide single connection. We are using following object for making connections,
const URL = `mongodb://db1.domain.com,db2.domain.com,db3.domain.com`;
const _mongodb = new MongoClient(URL, {
retryWrites: true,
w: 'majority',
replicaSet: 'rs0',
auth: {
username: process.env.MONGODB_USER,
password: process.env.MONGODB_PASS
},
tls: true,
tlsCertificateKeyFile: "file for tls certificate key",
tlsCAFile: "certificate file here"
retryReads: true,
retryWrites: true,
socketTimeoutMS: 0,
connectTimeoutMS: 0,
monitorCommands: true,
heartbeatFrequencyMS: 1000,
localThresholdMS: 1000,
maxPoolSize: 100,
});
}
console.log(`Attempting to connect to MongoDB: ${URL}`);
const start = new Date();
const client = await _mongodb.connect();
const durationMs = new Date().valueOf() - start.valueOf();
_database = _mongodb.db("v1"); //database version 1 in use
const MONGO_CLIENT_EVENTS = [ "connectionClosed", "error", "timeout", "close"];
//Adding connection closed event listners
MONGO_CLIENT_EVENTS.forEach(event => {
client.on(event, (e) => {
console.log('event', e);
})
});
Our application does thousands of database operations. The connection and the database operations were successful and worked in production environment without the network errors previously.
But When we upgraded the mongodb npm package that we use for database communications to version 6.4, the following error is coming up randomly.
MongoNetworkError: read ECONNRESET
at connectionFailureError (C:\app\node_modules\mongodb\lib\cmap\connect.js:357:20)
at TLSSocket.<anonymous> (C:\app\node_modules\mongodb\lib\cmap\connect.js:268:44)
at Object.onceWrapper (node:events:633:26)
at TLSSocket.emit (node:events:518:28)
at emitErrorNT (node:internal/streams/destroy:169:8)
at emitErrorCloseNT (node:internal/streams/destroy:128:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
connectionGeneration: 2,
[Symbol(errorLabels)]: Set(1) { 'ResetPool' },
[cause]: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read'
}
}
We have set the socketTimeoutMS: 0, and connectTimeoutMS: 0. So the socket won’t have timeout but the error indicates that mongodb connection is timed out.
This issue only occurs in mongodb Node.Js 6.0 and above.
Does anyone know about this issue/fixes?
We have tries to tune the connection options,
retryReads: true,
retryWrites: true,
socketTimeoutMS: 0,
connectTimeoutMS: 0,
monitorCommands: true,
heartbeatFrequencyMS: 1000,
localThresholdMS: 1000,
maxPoolSize: 100
We were expecting that we won’t see any MongoNetworkError: read ECONNRESET errors coming from mongodb when we upgrade the driver from 5.3 to 6.4.
Reaching out the community to see if anyone knows about any configs that we can set to mitigate such issues with mongo:6.0 or the native mongo driver from nodejs?