-
Notifications
You must be signed in to change notification settings - Fork 106
fix(connection): make pool not try to reconnect forever when reconnectTries = 0 #275
Conversation
I just came into the same issue 😭 When can we expect a review and merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I want to include a test. This will have to wait a day, or if someone gets a test in first we can merge immediately 😄
I'll work on putting in a test later today, but I think the most important thing here is to answer the question of whether the driver should try to reconnect in the background even after its rejected the promise and called the callback. I was always under the impression that the driver would not try to reconnect if initial connection failed, so I suspect this behavior is an unintentional quirk in the driver, but I'd like to hear @mbroadst 's thoughts on the matter. |
@vkarpov15 many of our other drivers have no concept of a |
@mbroadst that's fair. Do you want to remove that or should I? Also, I added a test 👍 |
@vkarpov15 thanks for the test! If I'm not mistaken shouldn't this fix correct the behavior we were discussing? Or rather: what are you referring to removing additionally? |
Not exactly. This provides a workaround to prevent the driver from attempting to reconnect if connection failed, but setting |
@mbroadst do you have any further comments on this issue? |
@vkarpov15 sorry for the delay, @mbroadst is on vacation. I will merge this in ASAP. |
This is a somewhat strange case. The below script will print an error immediately but continue retrying connecting in the background forever:
If you set
reconnectTries
to 1, the script prints an error and then exits.This patch fixes that particular issue. But this issue surfaced as part of investigating Automattic/mongoose#6028, which brings up a valid concern: why does the driver continue trying to reconnect and block process exit even after it rejects the
MongoClient.connect()
promise? I was under the impression that the driver would not try to reconnect after initial connection failed.