Closed arlindash closed 7 years ago
Thanks for your pr, it has two problems:
while (now - start < ms)
, you may need promise-retryI found that mongodb-core
has reconnect, and i tried it works well. so is this pr(handle reconnect by user) necessary?
MongoClient does have the reconnect mechanism. However, when the reconnect interval passes the mongo server instance pool gets destroyed. After that even if mongo is running again, when we acquire a new connection from the created pool, we will face the error of server instance pool being destroyed. To fix this issue we would have to restart the server, so that the mongoPool gets created again. What this code does is after acquiring a connection object, checks if the resource is connected to the mongo server. If it is not, it gives the MongoClient time to perform the retries, then checks the resource again. Only after the retry interval has passed and we did not get a connection, it creates a new pool.
Is there an update on this?
this PR seems very interesting and useful, do we will have soon a merge of it?
When mongo is down and the MongoClient has gone through the reconnectTries, the mongo server instance pool gets destroyed. This means that the server using the koa-mongo middleware will have to get restarted in order for koa-mongo to create a new connection pool. With this change, the acquired connection object is first checked if it is connected with the mongo server. If it is not, the middleware waits for the reconnect tries interval before creating a new pool and acquiring a new connection object.