Hi all,
It seems there is a strange error buffering timed out after 10000ms when i run the following code:
const mongoose = require(“mongoose”);
//mongoose.set(‘debug’, true);
//mongoose.set(‘bufferCommands’, false);
const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const userSchema = new mongoose.Schema({
name: String,
age: Number,
email: String,
});
const test = async (moduleDb, companyPrefix, pre) => {
let appDb = moduleDb.useDb(${companyPrefix}-local
, { useCache: true })
console.log(‘- Ready State:’, appDb.readyState)
const User = appDb.model(‘User’+pre, userSchema);
const newUser = new User({
name: ‘Alice’,
age: 25,
email: ‘alice@example.com’,
});
try {
const savedUser = await newUser.save();
console.log(‘- User inserted (•‿•)’);
} catch (error) {
console.error(‘Error inserting user:’, error);
}
try {
const foundUser = await User.findOne({ name: ‘Alice’ });
console.log(‘- User found (•‿•)’);
} catch (error) {
console.error(‘Error finding user:’, error);
}
await delay(10000)
}
const tests = async () => {
const conn = await mongoose.createConnection(
‘mongodb://root:******@127.0.0.1:27018/?authSource=admin&readPreference=primary&directConnection=true&ssl=false’,
{
readPreference: ‘nearest’,
maxPoolSize: 100,
family: 4,
connectTimeoutMS: 30000,
socketTimeoutMS: 30000,
serverSelectionTimeoutMS: 30000,
autoIndex:false,
}
).asPromise();
conn.on(‘disconnected’, async () => {
console.log(‘Connection lost, attempting to reconnect…’);
await conn.connect(); // Attempt to reconnect
});
await test(conn, ‘myCompany’,‘1’)
await test(conn, ‘myCompany’,‘2’)
await test(conn, ‘myCompany’,‘3’)
await test(conn, ‘myCompany’,‘4’)
await test(conn, ‘myCompany’,‘5’)
await test(conn, ‘myCompany’,‘6’)
}
tests()
if i run it with mongoose.set(‘bufferCommands’, false); it is working fine
Node 20.10.0 mongoose 8.7.0 linux
The strange is that it is working
- Ready State: 1
- User inserted (•‿•)
- User found (•‿•)
- Ready State: 1
- User inserted (•‿•)
- User found (•‿•)
- Ready State: 0
Error inserting user: MongooseError: Operationuser3.insertOne()
buffering timed out after 10000ms
and then the error happens and if i put the mongoose.set(‘bufferCommands’, false) it works fine: