This repository was archived by the owner on Feb 4, 2022. It is now read-only.
Resetting index when capping connection pool #54
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
After migrating to mongo driver 2.x we got this error (including here for full context):
Issue
Based on the stack trace, the only way to get
undefinedforconnectionin this line is if the pool'sindexis pointing to a wrong place in theconnectionsarray.After going through the code in
pool.jsthe only place where I could find that theindexinvariant is broken is incapConnections.Fix
To fix the issue I'm resetting the
indexwhen capping the connections if the current index value is invalid. The reason for choosing 0 is that it maintains the round-robin approach as the next valid connection would have been at index 0.I also added a check to verify that the
connectionactually exists in case there are any other issues with theconnectionspool, as otherwise an exception would crash apps.Let me know if you have any feedback.