Closed sw360cab closed 3 years ago
What debugger are you using?
v8-inspector
vithin VS Code.
@vkarpov15 does this answer your question?
I same problem: node:12.20.0 ubuntu:20.04 mongo:4.2.1 mongoose:5.11.7
if add useUnifiedTopology: true
let options = {
keepAlive: true,
connectTimeoutMS: 300000,
socketTimeoutMS: 300000,
useFindAndModify: false,
bufferMaxEntries: 0,
poolSize: 5,
useUnifiedTopology: true,
useNewUrlParser: true
};
const db = mongoose.createConnection(mongoUrl, options);
Error in mongodb connection: MongooseServerSelectionError: getaddrinfo EAI_AGAIN undefined
unhandledRejection Err:: MongooseServerSelectionError: getaddrinfo EAI_AGAIN undefined
at NativeConnection.Connection.openUri (/var/www/api_ES6/node_modules/mongoose/lib/connection.js:832:32)
at Mongoose.createConnection (/var/www/api_ES6/node_modules/mongoose/lib/index.js:285:17)
at file:///var/www/api_ES6/src/conn/conection.js:16:21
at ModuleJob.run (internal/modules/esm/module_job.js:145:37)
at async Loader.import (internal/modules/esm/loader.js:182:24)
at async Object.loadESM (internal/process/esm_loader.js:68:5) {
reason: TopologyDescription {
type: 'Unknown',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers: Map { 'undefined:27017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null
}
}
unhandledRejection Stack:: "MongooseServerSelectionError: getaddrinfo EAI_AGAIN undefined\n at NativeConnection.Connection.openUri (/var/www/api_ES6/node_modules/mongoose/lib/connection.js:832:32)\n at Mongoose.createConnection (/var/www/api_ES6/node_modules/mongoose/lib/index.js:285:17)\n at file:///var/www/api_ES6/src/conn/conection.js:16:21\n at ModuleJob.run (internal/modules/esm/module_job.js:145:37)\n at async Loader.import (internal/modules/esm/loader.js:182:24)\n at async Object.loadESM (internal/process/esm_loader.js:68:5)"
@jaffarc it looks more that you have EAI_AGAIN
variable undefined
rather than the timeout I am exposing
@sw360cab If I leave it as true a few seconds pass it will pop the error:
my string:
mongodb://userV2:1234@10.23.150.145:27017/v2_api?replicaSet=v2&authSource=v2_api&authMechanism=SCRAM-SHA-1&w=majority
If I let useNewUrlParser: false ,I stay connected normally. only with the alert message.
I forced the env into the conn file. and solved it ... Strange because when I put false he did not give the error. I was connected and only with warn msg
I haven't used node-inspector for debugging before, but I set it up and tried running the below script with a breakpoint on the first findOne()
:
'use strict';
const mongoose = require('mongoose');
mongoose.set('debug', true);
run().catch(err => console.log(err));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true
});
await mongoose.connection.dropDatabase();
const SchemaPerson = new mongoose.Schema({
_id: String,
name: String
});
const Person = mongoose.model('Person', SchemaPerson);
const doc = await Person.create({ _id: 'foo', name: 'CPU' });
await Person.findOne();
await Person.findOne();
console.log(doc._id);
}
Left the script hanging at the breakpoint for 30 seconds and resumed, no error.
Can you please come up with a script that repros this issue? It doesn't look like it happens with just any breakpoint in a Mongoose script.
Apparently with newest versions of mongoose lib this rarely happens and it is very hard to reproduce. I will update the issue if encounter it again.
When debugging a Node.js application both locally or remotely there is an annoying connection timeout that does not occur at all when the application is running without debug mode (not meaning strictly Mongoose debug) or stopping ar breakpoints.
The application is connecting to MongoDB via Mongoose with the following configuration:
Depending on the environment the connection to MongoDB can be toward:
localhost
remote host
via Docker network
MongoDB is usually running in a container exposing port 27017 (whether not in the same network stack with application)
At the moment nor replica set or other particular topolgies are in charge in this environment configuration
Lib versions
Apparently this did not happen with previous versions of Mongoose. Haven't tried yet, but the configuration above remained the same.
Step to reproduce
Run a Node.js app connecting to MongoDB via Mongoose in debug, stop at a breakpoint. Waiting few seconds and the following error message should show up:
Step to resolve
Apparently forcing
make the issue disappear. But as the comment left above says:
On the other side, it is now quite impossible to debug the application remotely when in Staging environment (or even worse production).