You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if the mongodb server is down then Service B is going to report wrongly "Connected successfully B..." .
The reason was nailed to the connect function of MongooseDbAdapter :
connect() {
let conn
if (this.model) {
if (mongoose.connection.readyState != 0) {
this.db = mongoose.connection;
return Promise.resolve();
}
conn = mongoose.connect(this.uri, this.opts);
} else if (this.schema) {
conn = mongoose.createConnection(this.uri, this.opts);
this.model = conn.model(this.modelName, this.schema);
}
return conn.then(result => {
this.db = result.connection || result.db;
this.db.on("disconnected", function mongoDisconnected() {
/* istanbul ignore next */
this.service.logger.warn("Disconnected from MongoDB.");
}.bind(this));
});
}
while executing service B it checks for mongoose.connection.readyState and after readyState 2 = connecting the Promise resolves simply because the status is connecting.
However under normal connection behavior this function resolves only when the connection is established.
This provokes the function afterConnected to be executed while there is no connection established.
Is there any different way to solve this issue without setting a dependency between services or using the schema instead of the model ?
The text was updated successfully, but these errors were encountered:
segpacto
changed the title
moleculer-db-adapter-mongoose report wrong connection state
moleculer-db-adapter-mongoose connect function resolves the Promise even when there is no connection established
Apr 24, 2019
The problem comes when the adapter-mongoose is used with multiple services which doesnt have dependencies between each other.
Service A
Service B
if the mongodb server is down then Service B is going to report wrongly "Connected successfully B..." .
The reason was nailed to the connect function of MongooseDbAdapter :
while executing service B it checks for
mongoose.connection.readyState
and after readyState2 = connecting
the Promise resolves simply because the status is connecting.However under normal connection behavior this function resolves only when the connection is established.
This provokes the function
afterConnected
to be executed while there is no connection established.Is there any different way to solve this issue without setting a dependency between services or using the schema instead of the model ?
The text was updated successfully, but these errors were encountered: