fix(client): Avoids infinite promise-chaining when socket's creation fails #2295
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.
Description
This change prevents a memory leak when a Redis client tries to connect to an unavailable host. This is achieve by switching from a recursive to an iterative approach.
When a Redis instance fails, our clients slowly build up memory until they get killed.
#2134
First, I had to slightly change the tests' implementation to work around timeout issues when running the tests, ie : specifying a timeout using the connectTimeout argument & giving up mocking time by specifying a very small retry delay. This commit should preferably be reverted if someone who manages to run tests locally can validate my implementation with the previous implementation for those tests 🤷
Second, I swapped the recursive call to
connect
for a do{}while loop and leverage the#this.isReady
property as the exit condition.Checklist
npm test
pass with this change (including linting)?