-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
createConnection does not reconnect when initializing the connection while the DB is down #6244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @tomgrossman tl;dr reconnect only applies to previously established connections. I was a little perplexed by this the first time I encountered it. This isn't a bug with mongoose but rather the intended behavior of the mongodb driver. There is at least one issue in mongodb's native driver bug tracker that proves we're not alone. Here is the link to the first one I found. |
the |
the current callback to the driver's MongoClient.connect method only emits an error and rejects the promise without changing the readyState. @vkarpov15 would it be a backwards breaking change to set the connection's readyState to disconnected in the initial error condition of the callback to .connect()? something like:
example:
output with .connect callback as it is now:
output with proposed change
|
@tomgrossman thanks for reporting, fixed in master and fix will be in 5.0.12 |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I'm initializing the DB connection with the
createConnection
function.If I'm doing so while the DB is down, the
readyState
of the connection stays at2
(connecting), and when starting the DB there is no re-connection until process restart.If the current behavior is a bug, please provide the steps to reproduce.
using the following script:
while the DB is down from the beginning, the console output is:
and the counter continues to go up on the
2
readyState
even when starting the DB in the middle.What is the expected behavior?
The connection should re-connect after starting the DB. The re-connection works fine if the DB goes down and up in the middle of the running process.
For example, using the same script as above when the DB is up at the beginning, and goes down and up in the middle of the run, the console output is:
Please mention your node.js, mongoose and MongoDB version.
node.js - 8.10.0
mongoose - 5.0.10
MongoDB - 3.4
The text was updated successfully, but these errors were encountered: