-
Type: Bug
-
Resolution: Gone away
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.2.3
-
Component/s: None
-
Labels:
-
Empty show more show less
Connection not closed if close called immediately after connecting to a replica set.
Introducing a Timeout delay allows the connection to be closed.
const MongoClient = require("mongodb").MongoClient; const mongodb_con_str = "mongodb://" + "localhost:27018,localhost:27019,localhost:27020" + "/test" + "?replicaSet=rs0"; const mongodb_con_opts = { "useNewUrlParser": true }; MongoClient.connect(mongodb_con_str, mongodb_con_opts) .then( mongo => Promise.reject() .then( _ => console.log("Program OK"), _ => console.log("Program error") ) // Adding a delay allows MongoClient.close() // to close the connection. //.then(_ => new Promise(r => setTimeout(r, 0))) .then(_ => mongo.close())) .catch(e => console.log("Program ended with error", e));